Perform query and field collapse

Viewed 565

When i do a multi-condition query and apply field collapsing to one of the field in the mentioned index i get following error

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

Query Used :

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

Error Trace:

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

Currently, am applying the query only for index - history but the result throws exception for indexes that i haven't mentioned. Please help how to narrow down field collapsing to a particular index.

1 Answers

It appears to be a bug, but if you notice your result carefully, you should be able to view the response you are looking for at the very end after all the such errors are observed.

But then again why not add the index name to the front and modify your query as below:

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