On executing elastic search and storing the result in JSON form
stdClass Object (
[took] => 119
[timed_out] =>
[_shards] => stdClass Object (
[total] => 5
[successful] => 5
[failed] => 0
)
[hits] => stdClass Object (
[total] => 3
[max_score] => 1
[hits] => Array (
[0] => stdClass Object (
[_index] => movies
[_type] => movie
[_id] => 3
[_score] => 1
[_source] => stdClass Object (
[title] => The MATRIX
[year] => 1975
)
)
[1] => stdClass Object (
[_index] => movies
[_type] => movie
[_id] => 8
[_score] => 1
[_source] => stdClass Object (
[title] => The MATRIX
[year] => 1975
)
)
[2] => stdClass Object (
[_index] => movies
[_type] => movie
[_id] => 4
[_score] => 1
[_source] => stdClass Object (
[title] => The MATRIX
[year] => 1975
)
)
)
)
)
I want to get value of each movie and year in the above
I tried
foreach($result as $i)
{
echo $i->title;
echo $i->year;
}
Notice: Trying to get property of non-object in D:\xampp\htdocs\esearch\index.php on line 16
Notice: Trying to get property of non-object in D:\xampp\htdocs\esearch\index.php on line 17
How to get it?
json_decode($yourjson, true).$iisn't an object (seeing how it's119, then empty, and then an stdClass.