Reputation: 33
I'm trying to output a multidimensional array containing the results of a query using ElasticSearch into a Laravel Blade template. This seems like it should be so simple but I can't seem to avoid Getting an Undefined index: title error - don't understand as title is in the array?
Array ( [took] => 4 [timed_out] => [_shards] => Array ( [total] => 5 [successful] => 5 [failed] => 0 ) [hits] => Array ( [total] => 1 [max_score] => 4.7465386 [hits] => Array ( [0] => Array ( [_index] => partnerpages [_type] => plugins [_id] => 1 [_score] => 4.7465386 [_source] => Array ( [title] => PPRSS RSS news feed plugin [description] => PPRSS plugin allows you to share your latest news [author] => Louise Johnson [tags] => Array ( [0] => RSS [1] => syndication [2] => content [3] => news [4] => feeds ) ) ) ) ) )
I think the first few arrays are standard output from ElasticSearch relating to speed etc of search query. I need to output plugin title, description, author and tags. I have tried various foreach loops e.g:
foreach ($plugins as $plugin) {
echo $plugin['title'];
echo $plugin['description'];
echo $plugin['author'];
echo $plugin['tags'];
}
Where $plugins is the output of my query via the controller.
Any help much appreciated - this is normally so simple (note I gave up on blade specific syntax and have just tried php).
Upvotes: 1
Views: 444
Reputation: 33
Thanks Val, this works:
foreach ($plugins['hits']['hits'] as $plugin) {
echo $plugin['_source']['title'];
echo $plugin['_source']['description'];
echo $plugin['_source']['author'];
}
Upvotes: 0