# Limiting buckets on histogram agg

**URL:** <https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610>\
**Category:** Elasticsearch\
**Created:** [September 3, 2014, 10:04pm UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610 "2014-09-03T22:04:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doug\_Nelson](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@Doug\_Nelson](https://discuss.elastic.co/u/Doug_Nelson)\
**Post date:** [September 3, 2014, 10:04pm UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/1 "2014-09-03T22:04:22Z")

</div>

So I am getting up to speed with elastic search and I was surprised to find  
no way to set the number of buckets for a histogram.

In my use case, I have a index of search clicks and one of the parameters  
is the item rank within returned search results.

I want to have an aggregation that shows the number search clicks in the  
first position, second position ....

So for this I need to set the interval to 1. But some of these can have a  
significant number of clicks with a very long tail with larger page ranks  
having very small number of clicks.

I would like to say to the histogram, just return me what is in the first  
20 buckets.

Seems like in addition to the interval, a size setting would also be needed  
to accomplish this.

I am trying to reproduce how the terms panel in Kibana works, but do not  
want to implement using facets, would rather do this with aggregations.

Thanks in advance

--  
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/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 3, 2014, 10:27pm UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/2 "2014-09-03T22:27:06Z")

</div>

Hi Doug,

I am not sure to understand what the aggregation that you are building  
looks like. Can you provide us with your aggregation and a example of what  
your documents look like?

On Thu, Sep 4, 2014 at 12:04 AM, Doug Nelson [doug.nelson@gmail.com](mailto:doug.nelson@gmail.com) wrote:

> So I am getting up to speed with Elasticsearch and I was surprised to  
> find no way to set the number of buckets for a histogram.
> 
> In my use case, I have a index of search clicks and one of the parameters  
> is the item rank within returned search results.
> 
> I want to have an aggregation that shows the number search clicks in the  
> first position, second position ....
> 
> So for this I need to set the interval to 1. But some of these can have  
> a significant number of clicks with a very long tail with larger page ranks  
> having very small number of clicks.
> 
> I would like to say to the histogram, just return me what is in the first  
> 20 buckets.
> 
> Seems like in addition to the interval, a size setting would also be  
> needed to accomplish this.
> 
> I am trying to reproduce how the terms panel in Kibana works, but do not  
> want to implement using facets, would rather do this with aggregations.
> 
> Thanks in advance
> 
> --  
> 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/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j5fPDgYYuxWP%2BP8gzeHKNqpxyAGo%2Bo5AFAykbWgfU7ozQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5fPDgYYuxWP%2BP8gzeHKNqpxyAGo%2Bo5AFAykbWgfU7ozQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 4, 2014, 2:25am UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/3 "2014-09-04T02:25:43Z")

</div>

Hello Doug ,

There is an issue for this -

> <https://github.com/elastic/elasticsearch/issues/2040>
>
> See
> https://groups.google.com/d/msg/elasticsearch/OZsc5ofNhag/9JfwSy-CEMwJ where… Shay says "...with the design of the facets, if shouldn't be hard to implement..."

Thanks  
Vineeth

On Thu, Sep 4, 2014 at 3:34 AM, Doug Nelson [doug.nelson@gmail.com](mailto:doug.nelson@gmail.com) wrote:

> So I am getting up to speed with Elasticsearch and I was surprised to  
> find no way to set the number of buckets for a histogram.
> 
> In my use case, I have a index of search clicks and one of the parameters  
> is the item rank within returned search results.
> 
> I want to have an aggregation that shows the number search clicks in the  
> first position, second position ....
> 
> So for this I need to set the interval to 1. But some of these can have  
> a significant number of clicks with a very long tail with larger page ranks  
> having very small number of clicks.
> 
> I would like to say to the histogram, just return me what is in the first  
> 20 buckets.
> 
> Seems like in addition to the interval, a size setting would also be  
> needed to accomplish this.
> 
> I am trying to reproduce how the terms panel in Kibana works, but do not  
> want to implement using facets, would rather do this with aggregations.
> 
> Thanks in advance
> 
> --  
> 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/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%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/CAGdPd5kisJ7pEP6Bhx-CE%3DtExnew3%3DZjTk3kDRt-\_%3DwaTDjXGA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kisJ7pEP6Bhx-CE%3DtExnew3%3DZjTk3kDRt-_%3DwaTDjXGA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [September 4, 2014, 2:29am UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/4 "2014-09-04T02:29:51Z")

</div>

Add this also - [Support for size and order in all bucket aggregations · Issue #6704 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/6704)  
, [Add "size" parameter to historgram aggregation (limit number of returned results) · Issue #7103 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/7103)

Thanks  
Vineeth

On Thu, Sep 4, 2014 at 7:55 AM, vineeth mohan [vm.vineethmohan@gmail.com](mailto:vm.vineethmohan@gmail.com)  
wrote:

> Hello Doug ,
> 
> There is an issue for this -  
> [Limit faceting to top N hits · Issue #2040 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2040)
> 
> Thanks  
> Vineeth
> 
> On Thu, Sep 4, 2014 at 3:34 AM, Doug Nelson [doug.nelson@gmail.com](mailto:doug.nelson@gmail.com) wrote:
> 
> > So I am getting up to speed with Elasticsearch and I was surprised to  
> > find no way to set the number of buckets for a histogram.
> > 
> > In my use case, I have a index of search clicks and one of the parameters  
> > is the item rank within returned search results.
> > 
> > I want to have an aggregation that shows the number search clicks in the  
> > first position, second position ....
> > 
> > So for this I need to set the interval to 1. But some of these can have  
> > a significant number of clicks with a very long tail with larger page ranks  
> > having very small number of clicks.
> > 
> > I would like to say to the histogram, just return me what is in the first  
> > 20 buckets.
> > 
> > Seems like in addition to the interval, a size setting would also be  
> > needed to accomplish this.
> > 
> > I am trying to reproduce how the terms panel in Kibana works, but do not  
> > want to implement using facets, would rather do this with aggregations.
> > 
> > Thanks in advance
> > 
> > --  
> > 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/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%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/CAGdPd5%3DasRRx3-KEX-WZf9XLRFo9o%2Bnhf8gOG8hPjwvAB5B12A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5%3DasRRx3-KEX-WZf9XLRFo9o%2Bnhf8gOG8hPjwvAB5B12A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Doug\_Nelson](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@Doug\_Nelson](https://discuss.elastic.co/u/Doug_Nelson)\
**Post date:** [September 4, 2014, 7:07pm UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/5 "2014-09-04T19:07:50Z")

</div>

thanks vineeth,

I +1 these in the issues.

I was able to solve this by using two queries and in the histogram buckets,  
I simply used a range filter to limit the number of buckets. Each bucket  
has the has the information I need, but I need to get the total count from  
the overall (without the range filter).

On Wednesday, September 3, 2014 9:29:58 PM UTC-5, vineeth mohan wrote:

> Add this also - [Support for size and order in all bucket aggregations · Issue #6704 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/6704)  
> , [Add "size" parameter to historgram aggregation (limit number of returned results) · Issue #7103 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/7103)
> 
> Thanks  
> Vineeth
> 
> On Thu, Sep 4, 2014 at 7:55 AM, vineeth mohan \<[vm.vine...@gmail.com](mailto:vm.vine...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hello Doug ,
> > 
> > There is an issue for this -  
> > [Limit faceting to top N hits · Issue #2040 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2040)
> > 
> > Thanks  
> > Vineeth
> > 
> > On Thu, Sep 4, 2014 at 3:34 AM, Doug Nelson \<[doug....@gmail.com](mailto:doug....@gmail.com)  
> > \<javascript:\>\> wrote:
> > 
> > > So I am getting up to speed with Elasticsearch and I was surprised to  
> > > find no way to set the number of buckets for a histogram.
> > > 
> > > In my use case, I have a index of search clicks and one of the  
> > > parameters is the item rank within returned search results.
> > > 
> > > I want to have an aggregation that shows the number search clicks in  
> > > the first position, second position ....
> > > 
> > > So for this I need to set the interval to 1. But some of these can  
> > > have a significant number of clicks with a very long tail with larger page  
> > > ranks having very small number of clicks.
> > > 
> > > I would like to say to the histogram, just return me what is in the  
> > > first 20 buckets.
> > > 
> > > Seems like in addition to the interval, a size setting would also be  
> > > needed to accomplish this.
> > > 
> > > I am trying to reproduce how the terms panel in Kibana works, but do not  
> > > want to implement using facets, would rather do this with aggregations.
> > > 
> > > Thanks in advance
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/df22a825-983f-4264-82c7-ed7e0f5718f0%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/f67f2bb8-2d08-4fbe-8e0c-839aa7b0bced%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f67f2bb8-2d08-4fbe-8e0c-839aa7b0bced%40googlegroups.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:04am UTC](https://discuss.elastic.co/t/limiting-buckets-on-histogram-agg/19610/6 "2017-07-06T01:04:17Z")

</div>


