# Time Zone

**URL:** <https://discuss.elastic.co/t/time-zone/6713>\
**Category:** Elasticsearch\
**Created:** [February 15, 2012, 12:02pm UTC](https://discuss.elastic.co/t/time-zone/6713 "2012-02-15T12:02:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yehuda\_Zargarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yehuda_zargarov/32/2164_2.png) [@Yehuda\_Zargarov](https://discuss.elastic.co/u/Yehuda_Zargarov)\
**Post date:** [February 15, 2012, 12:02pm UTC](https://discuss.elastic.co/t/time-zone/6713/1 "2012-02-15T12:02:51Z")

</div>

Hi,

I'm trying to use the time zone option within a date histogram, since  
the hour I get is greater than the hour saved in elastic (by 2 hours).  
I'm using 0.18.7.

This is my query:  
{"query":{"filtered":{"query":{"range":{"date":  
{"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
{"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}}

And it returns this:  
facets: {  
date\_sum\_stats: {  
\_type: date\_histogram  
entries: [  
{  
time: 1324184400000  
count: 2  
min: 5  
max: 10  
total: 15  
total\_count: 2  
mean: 7.5  
}  
{  
time: 1324188000000  
count: 1  
min: 35  
max: 35  
total: 35  
total\_count: 1  
mean: 35  
}  
]  
}

1324188000000 epoch is "08" in hours (doing Time.at(1324188000000 /  
1000).strftime("%H")) but the document is saved with the hour "06":  
users  
new\_user  
370563565  
1  
IE  
US  
11  
2011-12-18T06:00:00+00:00  
35

Any ideas?  
I've tried also with 2 as time zone and with no time zone at all, but  
always getting same (wrong) hours.

Thanks,

Yehuda Zargarov

---

<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:** [February 15, 2012, 1:34pm UTC](https://discuss.elastic.co/t/time-zone/6713/2 "2012-02-15T13:34:28Z")

</div>

You hit a problem with time zone rounding and date histogram for intervals lower than day. Its fixed in 0.19: [Date Histogram Facet: Improve time zone handling, add factor option · Issue #1580 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1580).

On Wednesday, February 15, 2012 at 2:02 PM, Yehuda Zargarov wrote:

> Hi,
> 
> I'm trying to use the time zone option within a date histogram, since  
> the hour I get is greater than the hour saved in elastic (by 2 hours).  
> I'm using 0.18.7.
> 
> This is my query:  
> {"query":{"filtered":{"query":{"range":{"date":  
> {"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
> ["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
> {"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}}
> 
> And it returns this:  
> facets: {  
> date\_sum\_stats: {  
> \_type: date\_histogram  
> entries: [  
> {  
> time: 1324184400000  
> count: 2  
> min: 5  
> max: 10  
> total: 15  
> total\_count: 2  
> mean: 7.5  
> }  
> {  
> time: 1324188000000  
> count: 1  
> min: 35  
> max: 35  
> total: 35  
> total\_count: 1  
> mean: 35  
> }  
> ]  
> }
> 
> 1324188000000 epoch is "08" in hours (doing Time.at ([http://Time.at](http://Time.at))(1324188000000 /  
> 1000).strftime("%H")) but the document is saved with the hour "06":  
> users  
> new\_user  
> 370563565  
> 1  
> IE  
> US  
> 11  
> 2011-12-18T06:00:00+00:00  
> 35
> 
> Any ideas?  
> I've tried also with 2 as time zone and with no time zone at all, but  
> always getting same (wrong) hours.
> 
> Thanks,
> 
> Yehuda Zargarov

---

<div class="post-metadata">

**Author:** ![Yehuda\_Zargarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yehuda_zargarov/32/2164_2.png) [@Yehuda\_Zargarov](https://discuss.elastic.co/u/Yehuda_Zargarov)\
**Post date:** [February 16, 2012, 3:03pm UTC](https://discuss.elastic.co/t/time-zone/6713/3 "2012-02-16T15:03:53Z")

</div>

Hi Shay,

Just installed elasticsearch-0.19.0.RC2, and still the "time\_zone"  
option on date histogram does not affect the result.

Thanks,

Yehuda Zargarov

On Feb 15, 3:34 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> You hit a problem with time zone rounding and date histogram for intervals lower than day. Its fixed in 0.19:[Date Histogram Facet: Improve time zone handling, add factor option · Issue #1580 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1580).
> 
> On Wednesday, February 15, 2012 at 2:02 PM, Yehuda Zargarov wrote:
> 
> > Hi,
> 
> > I'm trying to use the time zone option within a date histogram, since  
> > the hour I get is greater than the hour saved in elastic (by 2 hours).  
> > I'm using 0.18.7.
> 
> > This is my query:  
> > {"query":{"filtered":{"query":{"range":{"date":  
> > {"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
> > ["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
> > {"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}­}
> 
> > And it returns this:  
> > facets: {  
> > date\_sum\_stats: {  
> > \_type: date\_histogram  
> > entries: [  
> > {  
> > time: 1324184400000  
> > count: 2  
> > min: 5  
> > max: 10  
> > total: 15  
> > total\_count: 2  
> > mean: 7.5  
> > }  
> > {  
> > time: 1324188000000  
> > count: 1  
> > min: 35  
> > max: 35  
> > total: 35  
> > total\_count: 1  
> > mean: 35  
> > }  
> > ]  
> > }
> 
> > 1324188000000 epoch is "08" in hours (doing Time.at ([http://Time.at](http://Time.at))(1324188000000/  
> > 1000).strftime("%H")) but the document is saved with the hour "06":  
> > users  
> > new\_user  
> > 370563565  
> > 1  
> > IE  
> > US  
> > 11  
> > 2011-12-18T06:00:00+00:00  
> > 35
> 
> > Any ideas?  
> > I've tried also with 2 as time zone and with no time zone at all, but  
> > always getting same (wrong) hours.
> 
> > Thanks,
> 
> > Yehuda Zargarov- Hide quoted text -
> 
> - Show quoted text -

---

<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:** [February 16, 2012, 7:31pm UTC](https://discuss.elastic.co/t/time-zone/6713/4 "2012-02-16T19:31:39Z")

</div>

Then gist a full recreation, I will have a look. (see [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).

On Thursday, February 16, 2012 at 5:03 PM, Yehuda Zargarov wrote:

> Hi Shay,
> 
> Just installed elasticsearch-0.19.0.RC2, and still the "time\_zone"  
> option on date histogram does not affect the result.
> 
> Thanks,
> 
> Yehuda Zargarov
> 
> On Feb 15, 3:34 pm, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > You hit a problem with time zone rounding and date histogram for intervals lower than day. Its fixed in 0.19:[Date Histogram Facet: Improve time zone handling, add factor option · Issue #1580 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1580).
> > 
> > On Wednesday, February 15, 2012 at 2:02 PM, Yehuda Zargarov wrote:
> > 
> > > Hi,
> > 
> > > I'm trying to use the time zone option within a date histogram, since  
> > > the hour I get is greater than the hour saved in elastic (by 2 hours).  
> > > I'm using 0.18.7.
> > 
> > > This is my query:  
> > > {"query":{"filtered":{"query":{"range":{"date":  
> > > {"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
> > > ["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
> > > {"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}­}
> > 
> > > And it returns this:  
> > > facets: {  
> > > date\_sum\_stats: {  
> > > \_type: date\_histogram  
> > > entries: [  
> > > {  
> > > time: 1324184400000  
> > > count: 2  
> > > min: 5  
> > > max: 10  
> > > total: 15  
> > > total\_count: 2  
> > > mean: 7.5  
> > > }  
> > > {  
> > > time: 1324188000000  
> > > count: 1  
> > > min: 35  
> > > max: 35  
> > > total: 35  
> > > total\_count: 1  
> > > mean: 35  
> > > }  
> > > ]  
> > > }
> > 
> > > 1324188000000 epoch is "08" in hours (doing Time.at ([http://Time.at](http://Time.at))(1324188000000/  
> > > 1000).strftime("%H")) but the document is saved with the hour "06":  
> > > users  
> > > new\_user  
> > > 370563565  
> > > 1  
> > > IE  
> > > US  
> > > 11  
> > > 2011-12-18T06:00:00+00:00  
> > > 35
> > 
> > > Any ideas?  
> > > I've tried also with 2 as time zone and with no time zone at all, but  
> > > always getting same (wrong) hours.
> > 
> > > Thanks,
> > 
> > > Yehuda Zargarov- Hide quoted text -
> > 
> > - Show quoted text -

---

<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:** [February 16, 2012, 7:34pm UTC](https://discuss.elastic.co/t/time-zone/6713/5 "2012-02-16T19:34:16Z")

</div>

Note though, that the time\_zone in 0.19 just sets the pre\_zone, which basically applies the time zone before the rounding/bucketing, you might need to also pass post\_zone to convert the bucket data to a time zone from UTC. See more here: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html).

On Thursday, February 16, 2012 at 9:31 PM, Shay Banon wrote:

> Then gist a full recreation, I will have a look. (see [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)).
> 
> On Thursday, February 16, 2012 at 5:03 PM, Yehuda Zargarov wrote:
> 
> > Hi Shay,
> > 
> > Just installed elasticsearch-0.19.0.RC2, and still the "time\_zone"  
> > option on date histogram does not affect the result.
> > 
> > Thanks,
> > 
> > Yehuda Zargarov
> > 
> > On Feb 15, 3:34 pm, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > You hit a problem with time zone rounding and date histogram for intervals lower than day. Its fixed in 0.19:[Date Histogram Facet: Improve time zone handling, add factor option · Issue #1580 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1580).
> > > 
> > > On Wednesday, February 15, 2012 at 2:02 PM, Yehuda Zargarov wrote:
> > > 
> > > > Hi,
> > > 
> > > > I'm trying to use the time zone option within a date histogram, since  
> > > > the hour I get is greater than the hour saved in elastic (by 2 hours).  
> > > > I'm using 0.18.7.
> > > 
> > > > This is my query:  
> > > > {"query":{"filtered":{"query":{"range":{"date":  
> > > > {"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
> > > > ["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
> > > > {"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}­}
> > > 
> > > > And it returns this:  
> > > > facets: {  
> > > > date\_sum\_stats: {  
> > > > \_type: date\_histogram  
> > > > entries: [  
> > > > {  
> > > > time: 1324184400000  
> > > > count: 2  
> > > > min: 5  
> > > > max: 10  
> > > > total: 15  
> > > > total\_count: 2  
> > > > mean: 7.5  
> > > > }  
> > > > {  
> > > > time: 1324188000000  
> > > > count: 1  
> > > > min: 35  
> > > > max: 35  
> > > > total: 35  
> > > > total\_count: 1  
> > > > mean: 35  
> > > > }  
> > > > ]  
> > > > }
> > > 
> > > > 1324188000000 epoch is "08" in hours (doing Time.at ([http://Time.at](http://Time.at)) ([http://Time.at](http://Time.at))(1324188000000/  
> > > > 1000).strftime("%H")) but the document is saved with the hour "06":  
> > > > users  
> > > > new\_user  
> > > > 370563565  
> > > > 1  
> > > > IE  
> > > > US  
> > > > 11  
> > > > 2011-12-18T06:00:00+00:00  
> > > > 35
> > > 
> > > > Any ideas?  
> > > > I've tried also with 2 as time zone and with no time zone at all, but  
> > > > always getting same (wrong) hours.
> > > 
> > > > Thanks,
> > > 
> > > > Yehuda Zargarov- Hide quoted text -
> > > 
> > > - Show quoted text -

---

<div class="post-metadata">

**Author:** ![Yehuda\_Zargarov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yehuda_zargarov/32/2164_2.png) [@Yehuda\_Zargarov](https://discuss.elastic.co/u/Yehuda_Zargarov)\
**Post date:** [February 19, 2012, 4:14pm UTC](https://discuss.elastic.co/t/time-zone/6713/6 "2012-02-19T16:14:28Z")

</div>

post\_zone does the job. thanks.

On Feb 16, 9:34 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Note though, that the time\_zone in 0.19 just sets the pre\_zone, which basically applies the time zone before the rounding/bucketing, you might need to also pass post\_zone to convert the bucket data to a time zone from UTC. See more here:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/date-h)....
> 
> On Thursday, February 16, 2012 at 9:31 PM, Shay Banon wrote:
> 
> > Then gist a full recreation, I will have a look. (seehttp://www.elasticsearch.org/help).
> 
> > On Thursday, February 16, 2012 at 5:03 PM, Yehuda Zargarov wrote:
> 
> > > Hi Shay,
> 
> > > Just installed elasticsearch-0.19.0.RC2, and still the "time\_zone"  
> > > option on date histogram does not affect the result.
> 
> > > Thanks,
> 
> > > Yehuda Zargarov
> 
> > > On Feb 15, 3:34 pm, Shay Banon \<[kim...@gmail.com](mailto:kim...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > > 
> > > > You hit a problem with time zone rounding and date histogram for intervals lower than day. Its fixed in 0.19:[Date Histogram Facet: Improve time zone handling, add factor option · Issue #1580 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1580).
> 
> > > > On Wednesday, February 15, 2012 at 2:02 PM, Yehuda Zargarov wrote:
> > > > 
> > > > > Hi,
> 
> > > > > I'm trying to use the time zone option within a date histogram, since  
> > > > > the hour I get is greater than the hour saved in elastic (by 2 hours).  
> > > > > I'm using 0.18.7.
> 
> > > > > This is my query:  
> > > > > {"query":{"filtered":{"query":{"range":{"date":  
> > > > > {"from":"2011-12-18","to":"2011-12-18"}}},"filter":[{"terms":{"ctid":  
> > > > > ["11"]}}]}},"facets":{"date\_sum\_stats":{"date\_histogram":  
> > > > > {"key\_field":"date","value\_field":"sum","interval":"hour","time\_zone":-2}}}­}
> 
> > > > > And it returns this:  
> > > > > facets: {  
> > > > > date\_sum\_stats: {  
> > > > > \_type: date\_histogram  
> > > > > entries: [  
> > > > > {  
> > > > > time: 1324184400000  
> > > > > count: 2  
> > > > > min: 5  
> > > > > max: 10  
> > > > > total: 15  
> > > > > total\_count: 2  
> > > > > mean: 7.5  
> > > > > }  
> > > > > {  
> > > > > time: 1324188000000  
> > > > > count: 1  
> > > > > min: 35  
> > > > > max: 35  
> > > > > total: 35  
> > > > > total\_count: 1  
> > > > > mean: 35  
> > > > > }  
> > > > > ]  
> > > > > }
> 
> > > > > 1324188000000 epoch is "08" in hours (doing Time.at ([http://Time.at](http://Time.at)) ([http://Time.at](http://Time.at))(1324188000000/  
> > > > > 1000).strftime("%H")) but the document is saved with the hour "06":  
> > > > > users  
> > > > > new\_user  
> > > > > 370563565  
> > > > > 1  
> > > > > IE  
> > > > > US  
> > > > > 11  
> > > > > 2011-12-18T06:00:00+00:00  
> > > > > 35
> 
> > > > > Any ideas?  
> > > > > I've tried also with 2 as time zone and with no time zone at all, but  
> > > > > always getting same (wrong) hours.
> 
> > > > > Thanks,
> 
> > > > > Yehuda Zargarov- Hide quoted text -
> 
> > > > - Show quoted text -

---

<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:38am UTC](https://discuss.elastic.co/t/time-zone/6713/7 "2017-07-06T03:38:50Z")

</div>


