# Count how many values of field appears N times?

**URL:** <https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886>\
**Category:** Elasticsearch\
**Created:** [September 17, 2019, 10:02pm UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886 "2019-09-17T22:02:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcaballero](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jcaballero](https://discuss.elastic.co/u/jcaballero)\
**Post date:** [September 17, 2019, 10:02pm UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886/1 "2019-09-17T22:02:48Z")

</div>

Hi,

Elasticsearch 5.6

I see in the documentation how to count how many times each value of a field appears. But that is not exactly what I need.

My documents have a field _myfield_, of type _keyword_.  
I need to know how many different values of _myfield_ appear between 1 and 10 times. How many between 11 and 20 times. And so on. I don't care about their values, only their number of occurrences.

It feels to me the solution is some sort of compound aggregation, but not 100% clear how exactly, and I don't know the key words to search it myself. So any hint or direct link to documentation would be helpful.

Thanks.

---

<div class="post-metadata">

**Author:** ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)\
**Post date:** [September 18, 2019, 3:36am UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886/2 "2019-09-18T03:36:19Z")

</div>

You can use [terms aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-composite-aggregation.html) to get different values and their appear times. Then calculate the number of different values between 1 and 10 times, 11 and 20 times...by yourself.

---

<div class="post-metadata">

**Author:** ![jcaballero](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jcaballero](https://discuss.elastic.co/u/jcaballero)\
**Post date:** [September 20, 2019, 9:51pm UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886/3 "2019-09-20T21:51:26Z")

</div>

Hmm. Composite Aggregation seems to not be available in ES 5.6 ☹

---

<div class="post-metadata">

**Author:** ![jcaballero](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jcaballero](https://discuss.elastic.co/u/jcaballero)\
**Post date:** [September 23, 2019, 9:44pm UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886/4 "2019-09-23T21:44:40Z")

</div>

Investigating more in the documentation, I found a page [Pipelines Aggregations](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-pipeline.html)  
If that happens to help me with this use case, I will post here how.

---

<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 21, 2019, 9:44pm UTC](https://discuss.elastic.co/t/count-how-many-values-of-field-appears-n-times/199886/5 "2019-10-21T21:44:41Z")

</div>

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