# Is there anyway to return empty buckets/intervals for a histogram search on a Date field?

**URL:** <https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668>\
**Category:** Elasticsearch\
**Created:** [December 15, 2010, 9:07pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668 "2010-12-15T21:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![akmiller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akmiller/32/3294_2.png) [@akmiller](https://discuss.elastic.co/u/akmiller)\
**Post date:** [December 15, 2010, 9:07pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668/1 "2010-12-15T21:07:57Z")

</div>

I'm showing a chart that details activity between a start and an end  
date and I'm using ElasticSearch, along with the histogram query, to  
categorize my activity into 24 hour intervals. It seems ElasticSearch  
doesn't return all intervals (within my date range query), but instead  
only those that actually have data. Much of the time that probably  
makes the most sense and I'm guessing ElasticSearch doesn't even  
create the interval if there is no data for it.

However, my question is, is it possible to return all intervals, even  
those that have 0 data. I can obviously fill in the gaps in code after  
I have retrieved the results, it just seems like it might be more  
efficient if I could provide some type of parameter to the histogram  
query to instruct it to return all intervals.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 15, 2010, 10:40pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668/2 "2010-12-15T22:40:52Z")

</div>

It can certainly be implemented, but its a shame to do it since it might  
create considerable more data to return. It just felt to me that it makes  
much more sense to fill in the gaps on the client side, especially when most  
charting components out there can do it automatically.

On Wed, Dec 15, 2010 at 11:07 PM, akmiller [akmiller@gmail.com](mailto:akmiller@gmail.com) wrote:

> I'm showing a chart that details activity between a start and an end  
> date and I'm using Elasticsearch, along with the histogram query, to  
> categorize my activity into 24 hour intervals. It seems Elasticsearch  
> doesn't return all intervals (within my date range query), but instead  
> only those that actually have data. Much of the time that probably  
> makes the most sense and I'm guessing Elasticsearch doesn't even  
> create the interval if there is no data for it.
> 
> However, my question is, is it possible to return all intervals, even  
> those that have 0 data. I can obviously fill in the gaps in code after  
> I have retrieved the results, it just seems like it might be more  
> efficient if I could provide some type of parameter to the histogram  
> query to instruct it to return all intervals.

---

<div class="post-metadata">

**Author:** ![akmiller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akmiller/32/3294_2.png) [@akmiller](https://discuss.elastic.co/u/akmiller)\
**Post date:** [December 15, 2010, 10:56pm UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668/3 "2010-12-15T22:56:19Z")

</div>

That's why I was thinking it might be good as some type of parameter  
that I could send in to instruct it to do that. But I understand the  
sentiment of handling it client side as well. Thanks for the quick  
response.

On Dec 15, 4:40 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> It can certainly be implemented, but its a shame to do it since it might  
> create considerable more data to return. It just felt to me that it makes  
> much more sense to fill in the gaps on the client side, especially when most  
> charting components out there can do it automatically.
> 
> On Wed, Dec 15, 2010 at 11:07 PM, akmiller [akmil...@gmail.com](mailto:akmil...@gmail.com) wrote:
> 
> > I'm showing a chart that details activity between a start and an end  
> > date and I'm using Elasticsearch, along with the histogram query, to  
> > categorize my activity into 24 hour intervals. It seems Elasticsearch  
> > doesn't return all intervals (within my date range query), but instead  
> > only those that actually have data. Much of the time that probably  
> > makes the most sense and I'm guessing Elasticsearch doesn't even  
> > create the interval if there is no data for it.
> 
> > However, my question is, is it possible to return all intervals, even  
> > those that have 0 data. I can obviously fill in the gaps in code after  
> > I have retrieved the results, it just seems like it might be more  
> > efficient if I could provide some type of parameter to the histogram  
> > query to instruct it to return all intervals.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [December 19, 2010, 3:06am UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668/4 "2010-12-19T03:06:10Z")

</div>

Right. By the way, you can use the range facet to maybe work around that.  
For example, if you know in advance the ranges you want (for example, break  
a month into 4 weeks), then you can simply provide those 4 ranges.

On Thu, Dec 16, 2010 at 12:56 AM, akmiller [akmiller@gmail.com](mailto:akmiller@gmail.com) wrote:

> That's why I was thinking it might be good as some type of parameter  
> that I could send in to instruct it to do that. But I understand the  
> sentiment of handling it client side as well. Thanks for the quick  
> response.
> 
> On Dec 15, 4:40 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > It can certainly be implemented, but its a shame to do it since it might  
> > create considerable more data to return. It just felt to me that it makes  
> > much more sense to fill in the gaps on the client side, especially when  
> > most  
> > charting components out there can do it automatically.
> > 
> > On Wed, Dec 15, 2010 at 11:07 PM, akmiller [akmil...@gmail.com](mailto:akmil...@gmail.com) wrote:
> > 
> > > I'm showing a chart that details activity between a start and an end  
> > > date and I'm using Elasticsearch, along with the histogram query, to  
> > > categorize my activity into 24 hour intervals. It seems Elasticsearch  
> > > doesn't return all intervals (within my date range query), but instead  
> > > only those that actually have data. Much of the time that probably  
> > > makes the most sense and I'm guessing Elasticsearch doesn't even  
> > > create the interval if there is no data for it.
> > 
> > > However, my question is, is it possible to return all intervals, even  
> > > those that have 0 data. I can obviously fill in the gaps in code after  
> > > I have retrieved the results, it just seems like it might be more  
> > > efficient if I could provide some type of parameter to the histogram  
> > > query to instruct it to return all intervals.

---

<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, 4:15am UTC](https://discuss.elastic.co/t/is-there-anyway-to-return-empty-buckets-intervals-for-a-histogram-search-on-a-date-field/3668/5 "2017-07-06T04:15:10Z")

</div>


