# Need help with Terms Aggregation : buckets count

**URL:** <https://discuss.elastic.co/t/need-help-with-terms-aggregation-buckets-count/227948>\
**Category:** Elasticsearch\
**Created:** [April 14, 2020, 3:17pm UTC](https://discuss.elastic.co/t/need-help-with-terms-aggregation-buckets-count/227948 "2020-04-14T15:17:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IanCap](https://avatars.discourse-cdn.com/v4/letter/i/74df32/32.png) [@IanCap](https://discuss.elastic.co/u/IanCap)\
**Post date:** [April 14, 2020, 3:17pm UTC](https://discuss.elastic.co/t/need-help-with-terms-aggregation-buckets-count/227948/1 "2020-04-14T15:17:36Z")

</div>

Hi everyone !

I'm currently working on a query and want to count the numbers of hits returned.  
Given the following query :

```auto
GET /index*/_search
{
  "aggs": {
    "ip": {
      "terms": {
        "field": "ClientIP.ip",
        "min_doc_count": 10000,
        "size": 1000
        }
    }
  }
}

```

I get the following result :

```auto
"aggregations" : {
    "ip" : {
      "doc_count_error_upper_bound" : 363,
      "sum_other_doc_count" : 1888503,
      "buckets" : [
        {
          "key" : "XXX.YYY.ZZZ.AA",
          "doc_count" : 20408
        },
        {
          "key" : "BB.UUU.FFF.AA",
          "doc_count" : 15619
        },
        {
          "key" : "ZZ.EEE.HH.FOO",
          "doc_count" : 12009
        },
        {
...
...
...

```

I want to get the size of the array "buckets" aka counting the number of hits and have yet to succeed.

Adding a cardinality aggregation the following way doesn't give the wanted result

```auto
GET /index*/_search
{
  "aggs": {
    "ip": {
      "terms": {
        "field": "ClientIP.ip",
        "min_doc_count": 10000,
        "size": 1000
      },
      "aggs": {
        "test": {
            "cardinality": {
              "field": "ClientIP.ip"
            }
        }
      }
    }
  }
}

```

As i get :

```auto
"aggregations" : {
    "ip" : {
      "doc_count_error_upper_bound" : 363,
      "sum_other_doc_count" : XXXXXX,
      "buckets" : [
        {
          "key" : "XXX.YYY.ZZZ.AA",
          "doc_count" : 20408,
          "test" : {
            "value" : 1
          }
        },
        {
          "key" : "BB.UUU.FFF.AA",
          "doc_count" : 15619,
          "test" : {
            "value" : 1
          }
        },

```

I saw on a similar topic some options about \_count or buckets\_path but i can't use them with a terms aggregation :  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#\_special\_paths](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#_special_paths)

I'm looking for a hand here,

Thanks in advance,

Ian

---

<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:** [May 12, 2020, 3:17pm UTC](https://discuss.elastic.co/t/need-help-with-terms-aggregation-buckets-count/227948/2 "2020-05-12T15:17:41Z")

</div>

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