php - 注意:未定义索引:点击

标签 php elasticsearch

我有一个搜索查询,执行搜索查询后,我将$ result放入数组中。

我的PHP代码-

$contents = $client->search($params); // executing the search

$search = array($contents); // make the result $contents as a array
 for ($i = 0; $i < count($search); $i++) {
$search['hits']['total']['title'] = strip_tags($search['hits']['total']['title']); // Trying to access the title

生成数组----
Array ( 
    [0] => Array ( 
        [took] => 1 
        [timed_out] => 
        [_shards] => Array ( 
            [total] => 2 
            [successful] => 2 
            [failed] => 0 
        ) 
        [hits] => Array (     
            [total] => 1 
            [max_score] => 2.6818755 
            [hits] => Array ( 
                [0] => Array ( 
                    [_index] => myindex 
                    [_type] => mytype 
                    [_id] => p36d3742b982586d8d 
                    [_score] => 2.6818755 
                    [_source] => Array ( 
                        [title] => Salma Hayek  => Salma Hayeks... 
                        [source] => Hello 
                        [guid] => p36d3742b982586d8d 
                        [pub_id] => 54ae51e5 
                        [type] => news
                    ) 
                ) 
            ) 
        ) 
    ) 
) 

现在的问题是,每次我尝试访问显示为标题的标题时,注意:未定义索引:击中

我尝试过-
$search['hits']['total']['title'] = strip_tags($search['hits']['total']['title']);

$search['']['hits']['total']['title'] = strip_tags($search['']['hits']['total']['title']);

没什么对我有用,可能是一个简单的错误,任何人都知道我在哪里出错。

我也尝试过使用它----
$search[$i]['hits']['total']['title'] = strip_tags($search[$i]['hits']['total']['title']);

但是它返回了一个错误,例如:

Warning: Cannot use a scalar value as an array



如何获取我的标题?

最佳答案

您缺少$i,请使用$search[$i]['hits']

这是标题$search[$i]['hits']['hits'][0]['_source']['title']的地方

关于php - 注意:未定义索引:点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32186162/

相关文章:

php - 在 html 页面中找不到验证

elasticsearch - 如何区分几个应该从句的命中

elasticsearch - 如何从Web站点使用Elastic&Kibana收集日志和收集日志

java - 更新Elasticsearch文档时如何忽略空值字段?

apache-spark - Elasticsearch for Spark 3.0

java - 如何通过Elasticsearch中的嵌套字段计算多个唯一文档?

php - Zend Framework 教程 - 我不断收到 sql 错误 - 未知数据库

php - 在 Laravel 中保存表单数据的正确方法是什么(使用注入(inject)模型)?

php - 连接查询返回奇怪的结果

PHP - 在 SQL 选择查询中忽略 NULL