elasticsearch,foreach,Php,Laravel,elasticsearch,Foreach" /> elasticsearch,foreach,Php,Laravel,elasticsearch,Foreach" />

Php 如何在Laravel视图中输出ElasticSearch查询

Php 如何在Laravel视图中输出ElasticSearch查询,php,laravel,elasticsearch,foreach,Php,Laravel,elasticsearch,Foreach,我试图将包含使用ElasticSearch查询结果的多维数组输出到Laravel刀片模板中。这看起来应该很简单,但我似乎无法避免得到一个未定义的索引:title error-不理解,因为title在数组中 Array ( [took] => 4 [timed_out] => [_shards] => Array ( [total] => 5 [successful] => 5 [failed] => 0 ) [hits] => Array ( [tota

我试图将包含使用ElasticSearch查询结果的多维数组输出到Laravel刀片模板中。这看起来应该很简单,但我似乎无法避免得到一个未定义的索引:title error-不理解,因为title在数组中

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 ) ) ) ) ) )
我认为前几个数组是ElasticSearch的标准输出,与搜索查询的速度等有关。我需要输出插件标题,描述,作者和标签。我尝试过各种foreach循环,例如:

foreach ($plugins as $plugin) {
    echo $plugin['title'];
    echo $plugin['description'];
    echo $plugin['author'];
    echo $plugin['tags'];
}
其中$plugins是我通过控制器查询的输出


非常感谢任何帮助-这通常非常简单(注意,我放弃了特定于刀片的语法,只是尝试了php)。

谢谢Val,这很有效:

foreach ($plugins['hits']['hits'] as $plugin) {
            echo $plugin['_source']['title'];
            echo $plugin['_source']['description'];
            echo $plugin['_source']['author'];
        }

谢谢Val,这很有效:

foreach ($plugins['hits']['hits'] as $plugin) {
            echo $plugin['_source']['title'];
            echo $plugin['_source']['description'];
            echo $plugin['_source']['author'];
        }

你不需要迭代
$plugins['hits']['hits']
然后
echo$plugin[''u source']['title']
?非常感谢val,这很有效。我相信剩下的只有另一个数组中的标签。你不需要迭代
$plugins['hits']['hits']]
然后
echo$plugin[''u source']['title']
?非常感谢val,这很有效。唯一剩下的就是我相信在另一个数组中的标签。