# Is it possible to get a bucketed aggregation based on the count of values for a field?

**URL:** https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836
**Category:** Elasticsearch
**Created:** [May 30, 2014, 5:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836 "2014-05-30T17:00:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discuss.elastic.co/u/Mike)
#### Post date: [May 30, 2014, 5:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836/1 "2014-05-30T17:00:03Z")

</div>

For example, assume I have the following docs:

{user:"Mike"}  
{user:"John"}  
{user:"Mike"}  
{user:"Sara"}  
{user:"Sara"}  
{user:"Sara"}

I can do a terms agg on user and get:  
Sara: 3  
Mike: 2  
John: 1

What if I didn't care about the actual total number of terms per value, and  
instead just wanted them bucketed into say 2 bins, those that had counts  
\<=1, and those \>=2?  
Users Showing up \>= 2 Times: 2  
Users Showing up \< 2 Times: 1

The range agg seems to give me the flexibility that I want in creating  
buckets, that that is based on the actual numeric value of a field like  
score or price. Is there a way to do the above without iterating through  
the thousands of terms myself on the client side?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4f36c603-eb3b-45a0-ad73-dd6f97a5a0fa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4f36c603-eb3b-45a0-ad73-dd6f97a5a0fa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![ElasticSearch\_Users\_](https://avatars.discourse-cdn.com/v4/letter/e/b4bc9f/32.png) [@ElasticSearch\_Users\_](https://discuss.elastic.co/u/ElasticSearch_Users_)
#### Post date: [May 30, 2014, 6:09pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836/2 "2014-05-30T18:09:19Z")

</div>

I don't believe this is possible at the moment. If you can pre-process your  
data and produce this summarization indexed into ES:

Sara: 3  
Mike: 2  
John: 1

Then you can use the range (or filter) agg as you already mentioned.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discuss.elastic.co/u/Mike)
#### Post date: [June 3, 2014, 9:27pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836/3 "2014-06-03T21:27:55Z")

</div>

Thanks. User is just 1 field in my docs, which actually represent all  
requests made to my system. What I would really like is to just get a  
count of the "heavy", "medium", and "light" users, where heavy would be  
users that have made say \> 10 requests. I guess what I would need would be  
something like a terms\_range agg.

On Fri, May 30, 2014 at 2:09 PM, 'Binh Ly' via elasticsearch \<  
[elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)\> wrote:

> I don't believe this is possible at the moment. If you can pre-process  
> your data and produce this summarization indexed into ES:
> 
> Sara: 3  
> Mike: 2  
> John: 1
> 
> Then you can use the range (or filter) agg as you already mentioned.
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/CtDhs0HDK2Q/unsubscribe](https://groups.google.com/d/topic/elasticsearch/CtDhs0HDK2Q/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a6741478-ff3d-4b47-a39a-5cb7332759bd%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAEhMYmMv5VxLFB0676QX4vpQW%3D%3DYFYk4Lzi2M2yrGMzCzet0Rg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAEhMYmMv5VxLFB0676QX4vpQW%3D%3DYFYk4Lzi2M2yrGMzCzet0Rg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:24am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-a-bucketed-aggregation-based-on-the-count-of-values-for-a-field/17836/4 "2017-07-06T01:24:50Z")

</div>


