Aggregation only over the search results

I found that the terms aggregations always inspect the entire collection, for example I use

{
    "query": {
        "match": {
            "text field": "some text"
        }
    },
    "aggs": {
        "agg-terms": {
            "terms": {
                "field": "my term field"
            }
        }
    }
  },

The system returns total=10000 while the document count in each bucket is about 200k (significantly greater than the total results). Can I limit the aggregations to only perform over returned results?

Aggregations do run across search results only.

10k is the max number of hits counted when track_total_hits is set to false (the default) and the figure is not accurate but “greater than equal”.

1 Like

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