# Timezones in date\_histogram

**URL:** <https://discuss.elastic.co/t/timezones-in-date-histogram/8635>\
**Category:** Elasticsearch\
**Created:** [August 4, 2012, 11:02pm UTC](https://discuss.elastic.co/t/timezones-in-date-histogram/8635 "2012-08-04T23:02:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@Darren](https://discuss.elastic.co/u/Darren)\
**Post date:** [August 4, 2012, 11:02pm UTC](https://discuss.elastic.co/t/timezones-in-date-histogram/8635/1 "2012-08-04T23:02:00Z")

</div>

Hi,

I'm trying to get my head wrapped around how timezones are used within a  
date\_histogram facet, I think I'm slightly confused!

Right now I have ~1mil docs with a timestamp field, each one stored with a  
+2:00 timezone. I limit a query with a date range also specifying the  
timezone as follows:  
"timestamp": {  
"from": "2012-07-05T14:27:14+02:00",  
"to": "2012-08-05T14:27:14+02:00",  
"include\_lower": true,  
"include\_upper": true  
}

However, if I specify date ranges set in -07:00 timezone things things get  
a little confusing.

Consider it is 2012-08-04 22:00+00:00 right now.  
If I set "time\_zone" in the date\_histogram facet to -07:00, the date  
buckets returned are missing everything within 2012-08-04 when actually  
there should be thousands - 15 hours worth.  
Trying to read the timezone docs on the guide (  
[http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html)),  
are the times returned actually in UTC despite the time\_zone setting? If  
this is the case, then it would make sense that I would need to set the  
post\_zone setting also to -07:00. However this pushes the times back as  
expected making things look worse.

Should I need to set post\_zone? If so, what to?

And as a side question, can you pass anything to post\_zone and ES simply  
adjusts the times returned while keeping the bucket counts the same? This  
seems odd.. if I've understood it correctly.

Thanks,  
Darren

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [August 6, 2012, 4:54pm UTC](https://discuss.elastic.co/t/timezones-in-date-histogram/8635/2 "2012-08-06T16:54:22Z")

</div>

I set "pre\_zone" to e.g. "-07:00" and "pre\_zone\_adjust\_large\_interval" to  
true. This returns buckets for the specified time zone that include all  
documents with timestamps that actually fall within the date range of each  
bucket.

---

<div class="post-metadata">

**Author:** ![Darren](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@Darren](https://discuss.elastic.co/u/Darren)\
**Post date:** [August 6, 2012, 7:35pm UTC](https://discuss.elastic.co/t/timezones-in-date-histogram/8635/3 "2012-08-06T19:35:58Z")

</div>

Not sure I understand why it's working but it definitely looks a lot more  
convincing now.. thanks!

On Mon, Aug 6, 2012 at 5:54 PM, Eric Jain [eric.jain@gmail.com](mailto:eric.jain@gmail.com) wrote:

> I set "pre\_zone" to e.g. "-07:00" and "pre\_zone\_adjust\_large\_interval" to  
> true. This returns buckets for the specified time zone that include all  
> documents with timestamps that actually fall within the date range of each  
> bucket.

---

<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, 3:17am UTC](https://discuss.elastic.co/t/timezones-in-date-histogram/8635/4 "2017-07-06T03:17:34Z")

</div>


