Timezone in ES Python Client

Hi All,

I'm new to ES Python Client (https://elasticsearch-py.readthedocs.io/en/master/) and have an odd issue on query result from Elasticsearch.search().
Queried data has a datetime field holding UTC timestamp but Elasticsearch.search() returns it in my local timezone, which is UTS+9.
It looks like Elasticsearch.search() automatically(by default?) converts the datetime field into my local timezone.

I'd like to confirm if this is an expected behavior and how I can set customized timezone in Elasticsearch.search().

Many thanks in advance for your help!
Regards,
Sat

Hi @shin1,

I don't think it converts datetime fields to local timezone. Please take a look in the following example:

#Index one document in UTC
POST index/doc/1
{
  "date": "2018-01-12T00:00:00Z"
} 

Search using elasticsearch-py:

from elasticsearch import Elasticsearch

es = Elasticsearch()
result = es.search(index="index", body={
    "query": {
        "range": {
            "date": {
                "gte": "2018||/y"
            }
        }
    }
})
print result["hits"]["hits"][0]["_source"]["date"]

Execute the code:

$ python search_date.py
$ 2018-01-12T00:00:00Z  --> as indexed

I'm in UTC -2:00

Cheers,
LG

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