Elasticsearch- How to make the aggregation to return only the key matched

I'm using elasticsearch 6.2.3 and i'm trying to make a filter on the aggregation to return only the keys matched not all of them from the buckets. Or maybe i need to do a script and iterate over the buckets to get only the match? My query is:

 {
"aggs" : {
    "genres" : {
           "nested" : {
            "path" : "tags"
        },
        "aggs": {
          "d":{
        "terms" : { "field" : "tags.values.value.facet"
        },
        "aggs": {
          "NAME": {
            "filter": {
              "prefix": {
                "tags.values.value.facet": "Variatio"
              }
            }
          }
        }
      }
    }
  }                 
}}

And the result looks like that:

"aggregations": {
"genres": {
  "doc_count": 285391,
  "d": {
    "doc_count_error_upper_bound": 0,
    "sum_other_doc_count": 44437,
    "buckets": [
      {
        "key": "null",
        "doc_count": 251811,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMAkku",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMBaden",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMEttlingen",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMEurope",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMGermany",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      },
      {
        "key": "MMKarlsruhe",
        "doc_count": 15870,
        "NAME": {
          "doc_count": 0
        }
      }
      }

Any suggestions?

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.