# Elastic simple search considering timezones

**URL:** <https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847>\
**Category:** Elasticsearch\
**Created:** [November 27, 2012, 5:07pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847 "2012-11-27T17:07:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 5:07pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/1 "2012-11-27T17:07:43Z")

</div>

Hi all,

I have an issue that requires timezone handling, meaning that I need to use  
dates given by user (in a certain timezone) to search in ES.  
All dates indexed to ES are UTC, and what I'm looking for is a way to tell  
ES that query dates are in a certain timezone, which internally would do  
the maths to turn them to UTC and give me back results in the user timezone.

Is this possible?

Thanks!

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 5:22pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/2 "2012-11-27T17:22:27Z")

</div>

On Tue, 2012-11-27 at 09:07 -0800, Vania S. wrote:

> Hi all,
> 
> I have an issue that requires timezone handling, meaning that I need  
> to use dates given by user (in a certain timezone) to search in ES.  
> All dates indexed to ES are UTC, and what I'm looking for is a way to  
> tell ES that query dates are in a certain timezone, which internally  
> would do the maths to turn them to UTC and give me back results in the  
> user timezone.

What do you mean by "give me back results in the user timezone"?

You get back the original document (unless you're talking about facets).

But, you can do eg a range filter and include the timezone information  
in the date:

{ range: { my\_date: { gte: "2012-01-01T09:00:00+03:00" }}}

clint

--

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 5:26pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/3 "2012-11-27T17:26:06Z")

</div>

Hi,

Thanks for your answer.

I meant, "give me back results that match user timezone".  
My dates are indexed in this format "yyyy-mm-dd hh:mm:ss" and that is also  
the format user is expecting to insert in queries.

Thanks,

On Tuesday, November 27, 2012 5:22:35 PM UTC, Clinton Gormley wrote:

> On Tue, 2012-11-27 at 09:07 -0800, Vania S. wrote:
> 
> > Hi all,
> > 
> > I have an issue that requires timezone handling, meaning that I need  
> > to use dates given by user (in a certain timezone) to search in ES.  
> > All dates indexed to ES are UTC, and what I'm looking for is a way to  
> > tell ES that query dates are in a certain timezone, which internally  
> > would do the maths to turn them to UTC and give me back results in the  
> > user timezone.
> 
> What do you mean by "give me back results in the user timezone"?
> 
> You get back the original document (unless you're talking about facets).
> 
> But, you can do eg a range filter and include the timezone information  
> in the date:
> 
> { range: { my\_date: { gte: "2012-01-01T09:00:00+03:00" }}}
> 
> clint

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 5:29pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/4 "2012-11-27T17:29:53Z")

</div>

> I meant, "give me back results that match user timezone".  
> My dates are indexed in this format "yyyy-mm-dd hh:mm:ss" and that is  
> also the format user is expecting to insert in queries.

As I said, you get back exactly what you put in, so no - you would have  
to handle that conversion in your application

clint

> Thanks,
> 
> On Tuesday, November 27, 2012 5:22:35 PM UTC, Clinton Gormley wrote:  
> On Tue, 2012-11-27 at 09:07 -0800, Vania S. wrote:  
> \> Hi all,  
> \>  
> \>  
> \> I have an issue that requires timezone handling, meaning  
> that I need  
> \> to use dates given by user (in a certain timezone) to search  
> in ES.  
> \> All dates indexed to ES are UTC, and what I'm looking for is  
> a way to  
> \> tell ES that query dates are in a certain timezone, which  
> internally  
> \> would do the maths to turn them to UTC and give me back  
> results in the  
> \> user timezone.
> 
> ```
> What do you mean by "give me back results in the user
> timezone"? 
>     
> You get back the original document (unless you're talking
> about facets). 
>     
> But, you can do eg a range filter and include the timezone
> information 
> in the date: 
>     
> { range: { my_date: { gte: "2012-01-01T09:00:00+03:00" }}} 
>     
> clint 
> 
> ```
> 
> --

--

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 5:30pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/5 "2012-11-27T17:30:40Z")

</div>

Thanks clint!

On Tuesday, November 27, 2012 5:07:43 PM UTC, Vania S. wrote:

> Hi all,
> 
> I have an issue that requires timezone handling, meaning that I need to  
> use dates given by user (in a certain timezone) to search in ES.  
> All dates indexed to ES are UTC, and what I'm looking for is a way to tell  
> ES that query dates are in a certain timezone, which internally would do  
> the maths to turn them to UTC and give me back results in the user timezone.
> 
> Is this possible?
> 
> Thanks!

--

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 6:15pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/6 "2012-11-27T18:15:28Z")

</div>

By the way, the date math can be used in this case?

To do something like:

{  
"filter": {  
"range": {  
"creationDate": {  
"from": "2012-11-21 11:48:31||+1h",  
"to": "2012-11-21 11:48:31",  
"include\_lower": true,  
"include\_upper": true  
}  
}  
}  
}

Thanks!

On Tuesday, November 27, 2012 5:30:40 PM UTC, Vania S. wrote:

> Thanks clint!
> 
> On Tuesday, November 27, 2012 5:07:43 PM UTC, Vania S. wrote:
> 
> > Hi all,
> > 
> > I have an issue that requires timezone handling, meaning that I need to  
> > use dates given by user (in a certain timezone) to search in ES.  
> > All dates indexed to ES are UTC, and what I'm looking for is a way to  
> > tell ES that query dates are in a certain timezone, which internally would  
> > do the maths to turn them to UTC and give me back results in the user  
> > timezone.
> > 
> > Is this possible?
> > 
> > Thanks!

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 6:18pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/7 "2012-11-27T18:18:24Z")

</div>

On Tue, 2012-11-27 at 10:15 -0800, Vania S. wrote:

> By the way, the date math can be used in this case?

yes, but it won't change the date formats that are returned to you. So  
this has the same effect as my example in the first email

clint

> To do something like:
> 
> {  
> "filter": {  
> "range": {  
> "creationDate": {  
> "from": "2012-11-21 11:48:31||+1h",  
> "to": "2012-11-21 11:48:31",  
> "include\_lower": true,  
> "include\_upper": true  
> }  
> }  
> }  
> }
> 
> Thanks!
> 
> On Tuesday, November 27, 2012 5:30:40 PM UTC, Vania S. wrote:  
> Thanks clint!
> 
> ```
> On Tuesday, November 27, 2012 5:07:43 PM UTC, Vania S. wrote:
> Hi all,
>             
>             
> I have an issue that requires timezone handling,
> meaning that I need to use dates given by user (in a
> certain timezone) to search in ES.
> All dates indexed to ES are UTC, and what I'm looking
> for is a way to tell ES that query dates are in a
> certain timezone, which internally would do the maths
> to turn them to UTC and give me back results in the
> user timezone.
>             
>             
> Is this possible?
>             
>             
> Thanks!
> 
> ```
> 
> --

--

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 6:24pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/8 "2012-11-27T18:24:24Z")

</div>

True, but this way I don't have to change my indexed date formats... I can  
still have "yyyy-mm-dd hh:mm:ss" and just add the "timezone" as ||+/+TZh,  
right?

On Tue, Nov 27, 2012 at 6:18 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> On Tue, 2012-11-27 at 10:15 -0800, Vania S. wrote:
> 
> > By the way, the date math can be used in this case?
> 
> yes, but it won't change the date formats that are returned to you. So  
> this has the same effect as my example in the first email
> 
> clint
> 
> > To do something like:
> > 
> > {  
> > "filter": {  
> > "range": {  
> > "creationDate": {  
> > "from": "2012-11-21 11:48:31||+1h",  
> > "to": "2012-11-21 11:48:31",  
> > "include\_lower": true,  
> > "include\_upper": true  
> > }  
> > }  
> > }  
> > }
> > 
> > Thanks!
> > 
> > On Tuesday, November 27, 2012 5:30:40 PM UTC, Vania S. wrote:  
> > Thanks clint!
> > 
> > ```
> > On Tuesday, November 27, 2012 5:07:43 PM UTC, Vania S. wrote:
> > Hi all,
> > 
> > I have an issue that requires timezone handling,
> > meaning that I need to use dates given by user (in a
> > certain timezone) to search in ES.
> > All dates indexed to ES are UTC, and what I'm looking
> > for is a way to tell ES that query dates are in a
> > certain timezone, which internally would do the maths
> > to turn them to UTC and give me back results in the
> > user timezone.
> > 
> > Is this possible?
> > 
> > Thanks!
> > 
> > ```
> > 
> > --
> 
> --

--  
_Vânia Santos_

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [November 27, 2012, 6:32pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/9 "2012-11-27T18:32:31Z")

</div>

On Tue, 2012-11-27 at 18:24 +0000, Vânia Santos wrote:

> True, but this way I don't have to change my indexed date formats... I  
> can still have "yyyy-mm-dd hh:mm:ss" and just add the "timezone" as ||  
> +/+TZh, right?

Yes, but I never suggested that you did need to change your indexed date  
formats 🙂

clint

--

---

<div class="post-metadata">

**Author:** ![vannya](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vannya](https://discuss.elastic.co/u/vannya)\
**Post date:** [November 27, 2012, 10:15pm UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/10 "2012-11-27T22:15:20Z")

</div>

I'll try either ways!

Thanks!

On Tue, Nov 27, 2012 at 6:32 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> On Tue, 2012-11-27 at 18:24 +0000, Vânia Santos wrote:
> 
> > True, but this way I don't have to change my indexed date formats... I  
> > can still have "yyyy-mm-dd hh:mm:ss" and just add the "timezone" as ||  
> > +/+TZh, right?
> 
> Yes, but I never suggested that you did need to change your indexed date  
> formats 🙂
> 
> clint
> 
> --

--  
_Vânia Santos_

--

---

<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:02am UTC](https://discuss.elastic.co/t/elastic-simple-search-considering-timezones/9847/11 "2017-07-06T03:02:34Z")

</div>


