# Date Histogram Facet and interval. How does it work under covers?

**URL:** <https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868>\
**Category:** Elasticsearch\
**Created:** [February 24, 2013, 8:35pm UTC](https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868 "2013-02-24T20:35:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Kutcharian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drew_kutcharian/32/742_2.png) [@Drew\_Kutcharian](https://discuss.elastic.co/u/Drew_Kutcharian)\
**Post date:** [February 24, 2013, 8:35pm UTC](https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868/1 "2013-02-24T20:35:12Z")

</div>

Hi Guys,

I'm trying to better understand how the Date Histogram Facet works.

Say I want to get the histogram for a whole year at "month" interval vs get the histogram for a day at "minute" interval. Does ES actually count EVERY document that matches the query? Meaning the operation is the same regardless of the interval?

If so, how do you optimize this for a large number of documents and long periods of time, i.e. millions of documents in a year but drawing a monthly trend chart? Does the sharing of indexes based on time time that Shay talked about in [https://speakerdeck.com/kimchy/elasticsearch-big-data-search-analytics](https://speakerdeck.com/kimchy/elasticsearch-big-data-search-analytics) help in this use case?

Thanks,

Drew

--  
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:** ![Karel\_Minarik\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karel_minarik_2/32/1078_2.png) [@Karel\_Minarik\_2](https://discuss.elastic.co/u/Karel_Minarik_2)\
**Post date:** [February 25, 2013, 5:54am UTC](https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868/2 "2013-02-25T05:54:34Z")

</div>

> Say I want to get the histogram for a whole year at "month" interval vs  
> get the histogram for a day at "minute" interval. Does ES actually count  
> EVERY document that matches the query? Meaning the operation is the same  
> regardless of the interval?

Yes, but you sound concerned about performance / speed -- Elasticsearch  
uses dedicated caches for faceting; it does not "iterate" over every  
document in the matching set. So the optimization is already there. Of  
course, you always win, when you can split the data, and date histogram is  
no different. Though, in my experience, it's _very_ fast.

Karel

--  
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:** ![Drew\_Kutcharian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drew_kutcharian/32/742_2.png) [@Drew\_Kutcharian](https://discuss.elastic.co/u/Drew_Kutcharian)\
**Post date:** [February 25, 2013, 8:49pm UTC](https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868/3 "2013-02-25T20:49:01Z")

</div>

Hi Karel,

Can you give me some numbers that you've seen in the wild? What I'm looking mainly is to find out how much memory/time will be required to process a monthly histogram of say 1 billion documents that all match the query. (To be able to draw a nice chart)

-- Drew

On Feb 24, 2013, at 9:54 PM, Karel Minařík [karel.minarik@elasticsearch.com](mailto:karel.minarik@elasticsearch.com) wrote:

> Say I want to get the histogram for a whole year at "month" interval vs get the histogram for a day at "minute" interval. Does ES actually count EVERY document that matches the query? Meaning the operation is the same regardless of the interval?
> 
> Yes, but you sound concerned about performance / speed -- Elasticsearch uses dedicated caches for faceting; it does not "iterate" over every document in the matching set. So the optimization is already there. Of course, you always win, when you can split the data, and date histogram is no different. Though, in my experience, it's _very_ fast.
> 
> Karel
> 
> --  
> 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).

--  
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:49am UTC](https://discuss.elastic.co/t/date-histogram-facet-and-interval-how-does-it-work-under-covers/10868/4 "2017-07-06T02:49:36Z")

</div>


