# Can you do date histogram with specified number of buckets?

**URL:** https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18305
**Category:** Elasticsearch
**Created:** [June 24, 2014, 6:07pm UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18305 "2014-06-24T18:07:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tebring\_Daly](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@Tebring\_Daly](https://discuss.elastic.co/u/Tebring_Daly)
#### Post date: [June 24, 2014, 6:07pm UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18305/1 "2014-06-24T18:07:19Z")

</div>

Looks like the histogram aggregation works currently where each bucket is  
based on a user defined time interval, therefore you do not know how many  
buckets you will be returned unless you know ahead of time how much time  
your data spans.

Is there a way to create a date histogram aggregation in ElasticSearch  
where I can define the number of buckets that I want and the bucket  
increment be determined during execution based on the oldest and newest  
matching document?

I would like to be able to say give me 20 buckets. Thus if the data spans  
10 years each bucket is determined a half year, or if it spans 10 minutes  
each bucket determined to be 30 seconds.

Thanks!

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

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 30, 2014, 7:13am UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18305/2 "2014-06-30T07:13:34Z")

</div>

Hey,

right now the interval needs to be defined on query time and is never  
dynamically calculated. The main reason is, that for each new document, you  
probably have to expand the buckets or you have to have a first to  
predetermine the oldest and youngest date of the dataset, which requires an  
additional roundtrip across the cluster (also the bucket expansion would  
need to occur cross cluster, which sounds like quite an performance impact,  
but I am not an aggregregations expert).

--Alex

On Tue, Jun 24, 2014 at 8:07 PM, Tebring Daly [tdalytx@gmail.com](mailto:tdalytx@gmail.com) wrote:

> Looks like the histogram aggregation works currently where each bucket is  
> based on a user defined time interval, therefore you do not know how many  
> buckets you will be returned unless you know ahead of time how much time  
> your data spans.
> 
> Is there a way to create a date histogram aggregation in Elasticsearch  
> where I can define the number of buckets that I want and the bucket  
> increment be determined during execution based on the oldest and newest  
> matching document?
> 
> I would like to be able to say give me 20 buckets. Thus if the data spans  
> 10 years each bucket is determined a half year, or if it spans 10 minutes  
> each bucket determined to be 30 seconds.
> 
> Thanks!
> 
> --  
> 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/CAPPbrSSJmC4rwfpaOYpygEpA\_cjuaTXLLSyVaS4WFRGJEkSLDA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPPbrSSJmC4rwfpaOYpygEpA_cjuaTXLLSyVaS4WFRGJEkSLDA%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAPPbrSSJmC4rwfpaOYpygEpA\_cjuaTXLLSyVaS4WFRGJEkSLDA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAPPbrSSJmC4rwfpaOYpygEpA_cjuaTXLLSyVaS4WFRGJEkSLDA%40mail.gmail.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/CAGCwEM9zQwMuG\_NxTk6iJer9QKfNJ4-osiBpQicNvn1%2B-Xp3yg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM9zQwMuG_NxTk6iJer9QKfNJ4-osiBpQicNvn1%2B-Xp3yg%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:19am UTC](https://discuss.elastic.co/t/can-you-do-date-histogram-with-specified-number-of-buckets/18305/3 "2017-07-06T01:19:02Z")

</div>


