# Date Histogram - Automatically Setting Interval for Nice Bar Charts

**URL:** <https://discuss.elastic.co/t/date-histogram-automatically-setting-interval-for-nice-bar-charts/14308>\
**Category:** Elasticsearch\
**Created:** [November 7, 2013, 5:09pm UTC](https://discuss.elastic.co/t/date-histogram-automatically-setting-interval-for-nice-bar-charts/14308 "2013-11-07T17:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [November 7, 2013, 5:09pm UTC](https://discuss.elastic.co/t/date-histogram-automatically-setting-interval-for-nice-bar-charts/14308/1 "2013-11-07T17:09:33Z")

</div>

Hi,

Is there any way for Elastic Search to automatically select the interval  
for a date histogram facet based on a simple heuristic? This is useful for  
creating pretty bar charts without guessing a good interval size (like here[https://www.docketalarm.com/search/PTAB/dockets/?q=petition&s=on](https://www.docketalarm.com/search/PTAB/dockets/?q=petition&s=on),  
and see below, for example).

Ideally, the heuristic would be something like this:

- Set the interval to the smallest interval possible where there are at  
least X buckets.  
A reasonable value of X could be 5, but ideally could be adjusted.

When implementing this, you would want the bucket count to include empty  
buckets. For example, if there were two values, jan. 1, 1990, and Jan. 1.  
1992, and the interval was a year, then there would be 3 buckets, not 2. So  
if X was five, you would want to set interval to months.

Note that this issue is similar to automatically setting the bucket size  
for any histogram facet, not just date histograms.

Here's an example of a date\_histogram chart I am making:

[https://lh3.googleusercontent.com/-aHkIVXPZc6A/UnvIvpvVUzI/AAAAAAAACMU/QRgL4XJ\_SOs/s1600/chart.png](https://lh3.googleusercontent.com/-aHkIVXPZc6A/UnvIvpvVUzI/AAAAAAAACMU/QRgL4XJ_SOs/s1600/chart.png)  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [November 7, 2013, 6:35pm UTC](https://discuss.elastic.co/t/date-histogram-automatically-setting-interval-for-nice-bar-charts/14308/2 "2013-11-07T18:35:16Z")

</div>

I realized there was a typo in my heuristic. It should be:

- Set the interval to the _largest_ interval possible where there are at  
least X buckets.

On Thursday, November 7, 2013 12:09:33 PM UTC-5, Michael Sander wrote:

> Hi,
> 
> Is there any way for Elastic Search to automatically select the interval  
> for a date histogram facet based on a simple heuristic? This is useful for  
> creating pretty bar charts without guessing a good interval size (like  
> here [https://www.docketalarm.com/search/PTAB/dockets/?q=petition&s=on](https://www.docketalarm.com/search/PTAB/dockets/?q=petition&s=on),  
> and see below, for example).
> 
> Ideally, the heuristic would be something like this:
> 
> - Set the interval to the smallest interval possible where there are at  
> least X buckets.  
> A reasonable value of X could be 5, but ideally could be adjusted.
> 
> When implementing this, you would want the bucket count to include empty  
> buckets. For example, if there were two values, jan. 1, 1990, and Jan. 1.  
> 1992, and the interval was a year, then there would be 3 buckets, not 2. So  
> if X was five, you would want to set interval to months.
> 
> Note that this issue is similar to automatically setting the bucket size  
> for any histogram facet, not just date histograms.
> 
> Here's an example of a date\_histogram chart I am making:
> 
> [https://lh3.googleusercontent.com/-aHkIVXPZc6A/UnvIvpvVUzI/AAAAAAAACMU/QRgL4XJ\_SOs/s1600/chart.png](https://lh3.googleusercontent.com/-aHkIVXPZc6A/UnvIvpvVUzI/AAAAAAAACMU/QRgL4XJ_SOs/s1600/chart.png)  
> 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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:08am UTC](https://discuss.elastic.co/t/date-histogram-automatically-setting-interval-for-nice-bar-charts/14308/3 "2017-07-06T02:08:19Z")

</div>


