php - 使用嵌套字段进行多索引搜索

标签 php elasticsearch laravel-5 elasticsearch-2.0

我有两个索引:

首先,questions,具有嵌套字段answers。其次,articles没有此字段。

我尝试通过多个索引进行搜索:

{
    "index": "questions, articles",
    "body":{
        "query":{
            "bool":{
                "must":{
                    "nested":{
                        "path": "answer",
                        ...
                    }
                }
            }
        }
    }
}

并得到错误的"query_parsing_exception: [nested] failed to find nested object under path [answer]"
当一个索引具有嵌套字段,而另一个索引没有嵌套字段时,如何进行无错误搜索?

最佳答案

我认为您需要使用 indices query并对每个索引使用不同的查询。像这样:

GET /questions,articles/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "indices": {
                  "indices": [
                    "questions"
                  ],
                  "query": {
                    "nested": {
                      "path": "answer",
                      "query": {
                        "term": {
                          "text": "bla"
                        }
                      }
                    }
                  }
                }
              },
              {
                "match_all": {}
              }
            ]
          }
        },
        {
          "term": {
            "some_common_field": {
              "value": "whatever"
            }
          }
        }
      ]
    }
  }
}

关于php - 使用嵌套字段进行多索引搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975754/

相关文章:

PHP curl : Max Length on CURLOPT_USERPWD?

php - Paypal Pro 不在 magento 中显示运输方式

elasticsearch - 我可以在一个 Elasticsearch 索引设置中有多个过滤器吗?

elasticsearch - ElasticSearch-将索引还原到较低版本

elasticsearch - Elasticsearch无法使用lang groovy运行内联脚本[doc…]

javascript - Vue.js、Axios 对 Laravel API 的多个 get CORS 请求随机失败

mysql - 在 Laravel 中从数据库获取数据时出现错误

php - 如何从 MySQL 数据库中获取特定数据到我的 PHP 表中?

php - Doctrine:复杂的 JOIN 问题

php - Laravel 5.5 试图获取非对象的属性 'id'