elasticsearch

In Elasticsearch aggregations responses, how to drop "key_as_string" or "key" property?


I'm doing a multi terms aggregation in Elasticsearch, but in the response I have both keys and "key_as_string", which content is duplicated

{
          "key": [
            "99",
            "200"
          ],
          "key_as_string": "99|200",
          "doc_count": 1
        }

Is there any way to keep only one of the properties "key" or "key_as_string" ?

Thanks

I tried to do a multi terms aggregations using this query:

{
  "aggs": {
    "contexts": {
      "multi_terms": {
        "size": 100000000,
        "terms": [
          {
            "field": "context_1.id"
          },
          {
            "field": "context_2.id"
          }
        ]
      }
    }
  },
  "size": 0
}

Solution

  • I don't think you can remove the key_as_string explicitly. You could probably use filter_path to define which fields you want to include (and then not include key_as_string), but then you have to maintain a list of all the keys you do need... Like:

    GET /your_index/_search?filter_path=aggregations.contexts.buckets.key,aggregations.contexts.buckets.doc_count