Elasticsearch Timezone error?

In my mapping i defined

"Time": {
                  "type": "date",
                  "format": "strict_date_optional_time||epoch_millis"

When i used the following query

"range": {
                "Time": {
                  "gt": "now-1h"
                }
              }

Rather than showing the documents for last hour it showing the documents for past 3-4 hours.

My documents has Time field like this "Time": "2017-02-10T10:07:04.4367673+00:00"
I think it is in UTC format.
Thanks..

Yes, the date is stored in UTC format. The reason why I think you are seeing the past 3 - 4 hours is you are missing a "lt". A range should contain a gt and lt if you want to get a specific set of documents within a set timeframe - like the last hour.

"query": {
"range": {
"mydate": {
"gt": "now-10h",
"lt" : "now-9h"
}
}

Depending on the version of ES you are using, you can also use aggregation date_range / to & from / or you can store your dates in the timezone you want.

For example:

POST mytime2/mytimer
{
"mynum" : "2017-02-21T12:02:04.4367673-08:00"

}

See that in the last bit I put -08:00 , which converts the UTC to PST.

Thankyou jkuang :slight_smile:

:smiley: No problem, you're welcome.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.