Getting bucket size from response

Hello there.

Is there any way to get the bucket size (number of buckets) generated from a terms aggregation? I'm using the Java High Level client but couldn't find anything.

P.S: What I'm trying to get is the number 3 from the the first response example in here:

Any help is appreciated.

1 Like

Hi friend,

you could try "cardinality" aggregation, something like this:

    {
      "aggs": {
        "type_count": {
          "cardinality": {
            "field": "type"
          }
        }
      }
    }

and then the response ..

    {
      ...
      "aggregations": {
        "type_count": {
          "value": 3
        }
      }
    }

Cardinality aggregation | Elasticsearch Reference [7.10] | Elastic

Best regards..

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