# Getting bucket size from response

**URL:** <https://discuss.elastic.co/t/getting-bucket-size-from-response/263188>\
**Category:** Elasticsearch\
**Created:** [February 4, 2021, 2:26am UTC](https://discuss.elastic.co/t/getting-bucket-size-from-response/263188 "2021-02-04T02:26:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![araujonelson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/araujonelson/32/58133_2.png) [@araujonelson](https://discuss.elastic.co/u/araujonelson)\
**Post date:** [February 4, 2021, 2:26am UTC](https://discuss.elastic.co/t/getting-bucket-size-from-response/263188/1 "2021-02-04T02:26:24Z")

</div>

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:

> **[Terms aggregation | Elasticsearch Reference \[7.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)**

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Antonio\_Jose\_Robles](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antonio_jose_robles/32/76597_2.png) [@Antonio\_Jose\_Robles](https://discuss.elastic.co/u/Antonio_Jose_Robles)\
**Post date:** [February 9, 2021, 9:46pm UTC](https://discuss.elastic.co/t/getting-bucket-size-from-response/263188/2 "2021-02-09T21:46:45Z")

</div>

Hi friend,

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

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

```

and then the response ..

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

```

[Cardinality aggregation | Elasticsearch Reference [7.10] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html)

Best regards..

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 9, 2021, 9:47pm UTC](https://discuss.elastic.co/t/getting-bucket-size-from-response/263188/3 "2021-03-09T21:47:06Z")

</div>

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