# How to get total count in composite aggregation or any aggregation?

**URL:** <https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328>\
**Category:** Elasticsearch\
**Created:** [July 19, 2019, 6:58am UTC](https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328 "2019-07-19T06:58:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prakash.Panjwani](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Prakash.Panjwani](https://discuss.elastic.co/u/Prakash.Panjwani)\
**Post date:** [July 19, 2019, 6:58am UTC](https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328/1 "2019-07-19T06:58:13Z")

</div>

Hi,

I have documents with property tags{scope, tag} as nested document. I have used composite aggregation to find out unique tags available .

Composite aggregation does not return total number of buckets available.

I tried Scripted Metric aggregation to find out same, but it is taking almost 15 min.

> {  
> "size": 0,  
> "aggregations": {  
> "tags\_root": {  
> "nested": {  
> "path": "nested\_tags"  
> },  
> "aggregations": {  
> "composite\_scope\_tag": {  
> "scripted\_metric": {  
> "init\_script": {"source":"state.transactions = ","lang":"painless"},  
> "map\_script": {"source":"String tag\_scope = doc['nested\_tags.tag.keyword'].value + doc['nested\_tags.scope.keyword'].value; if(!state.transactions.contains(tag\_scope)){state.transactions.add(tag\_scope)}","lang":"painless"},  
> "combine\_script": {"source":"double count = 0; for (t in state.transactions) { count += 1 } return count","lang":"painless"},  
> "reduce\_script": {"source":"double totalCount = 0; for (a in states) { totalCount += a } return totalCount","lang":"painless"}  
> }  
> }  
> }  
> }  
> }  
> }

How i can get total count of Unique tags available in documents?

---

<div class="post-metadata">

**Author:** ![Prakash.Panjwani](https://avatars.discourse-cdn.com/v4/letter/p/2acd7d/32.png) [@Prakash.Panjwani](https://discuss.elastic.co/u/Prakash.Panjwani)\
**Post date:** [August 2, 2019, 5:57am UTC](https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328/2 "2019-08-02T05:57:30Z")

</div>

Do any one have idea regarding " [How to get total count in composite aggregation or any aggregation?](https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328)" ?

---

<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:** [August 30, 2019, 5:57am UTC](https://discuss.elastic.co/t/how-to-get-total-count-in-composite-aggregation-or-any-aggregation/191328/3 "2019-08-30T05:57:31Z")

</div>

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