首页 > 解决方案 > 执行查询和字段折叠

问题描述

当我进行多条件查询并将字段折叠应用于上述索引中的一个字段时,我收到以下错误

no mapping found for `search_type.keyword` in order to collapse on

使用的查询:

GET /_search
{
    "query": {
        "bool" : { 
      "must" : [
        {
         "match" : 
          { 
            "id" : "123456" 
          }
        },
        {
          "terms": {
            "_index": ["history"] 
          }
        }
      ]
    }
    },
    "collapse" : {
        "field" : "search_type.keyword",
         "inner_hits": {
        "name": "terms",
        "size": 10
        }
    }
}

错误跟踪:

{
        "shard" : 0,
        "index" : "test",
        "node" : "UOA44HkATh61krg6ht3paA",
        "reason" : {
          "type" : "illegal_argument_exception",
          "reason" : "no mapping found for `search_type.keyword` in order to collapse on"
        }
      }

目前,我只对索引应用查询 -历史,但结果对我没有提到的索引抛出异常。请帮助如何缩小字段折叠到特定索引的范围。

标签: elasticsearch

解决方案


这似乎是一个错误,但如果您仔细观察结果,在观察到所有此类错误后,您应该能够在最后查看您正在寻找的响应。

但是,为什么不将索引名称添加到前面并修改您的查询,如下所示:

POST history/_search                          <---- Add index name here
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "id": "123456"
          }
        }
      ]
    }
  },
  "collapse" : {
    "field" : "search_type.keyword",
    "inner_hits": {
      "name": "terms",
      "size": 10
    }
  }
}

推荐阅读