# How do I summarize the buckets from a term aggregation

**URL:** <https://discuss.elastic.co/t/how-do-i-summarize-the-buckets-from-a-term-aggregation/202033>\
**Category:** Elasticsearch\
**Created:** [October 2, 2019, 6:52pm UTC](https://discuss.elastic.co/t/how-do-i-summarize-the-buckets-from-a-term-aggregation/202033 "2019-10-02T18:52:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulY](https://avatars.discourse-cdn.com/v4/letter/p/ed655f/32.png) [@PaulY](https://discuss.elastic.co/u/PaulY)\
**Post date:** [October 2, 2019, 6:52pm UTC](https://discuss.elastic.co/t/how-do-i-summarize-the-buckets-from-a-term-aggregation/202033/1 "2019-10-02T18:52:18Z")

</div>

Hi I have query that looks like...

```
{
  "query": {
    "bool": {
      "must": [
        {"match": {"TxnCode.keyword": "XX"}}
      ]
    }
  },
  "size": 0,
  "aggs": {
      "date_buckets": {
      "terms": {
        "field": "Date.keyword",
        "order": {"_key": "desc"}
      },
      "aggs": {
        "terminal_buckets": {
            "terms": {
                "field": "TermID.keyword",
                "order": {"_key": "desc"}
            }
        }
    }
  }
}
}

```

This gives me a breakdown, by date, of how many times I see Terminal ID has TxnCode = XX. Ie:

Date : 2019-10-01

- Terminal1 : 6
- Terminal2 : 15
- Terminal3 : 10
- Terminal4 : 25

What I want now is to count the numbers of terminals group by number of occurances. Ie:

Date 2019-10-01

- 1 to 5 : 0
- 6 to 10: 2
- 11 to 20 : 1
- 20+ : 1

Is that possible?

Thanks  
Paul

---

<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:** [October 30, 2019, 6:52pm UTC](https://discuss.elastic.co/t/how-do-i-summarize-the-buckets-from-a-term-aggregation/202033/2 "2019-10-30T18:52:25Z")

</div>

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