How to set timezone when use python sdk?

  "_index": "mysql_backup_stat",
  "_type": "_doc",
  "_id": "addb-m15-2023-03-31T02:31:22.920268+08:00",
  "_version": 1,
  "_score": null,
  "_source": {
    "timestamp": "2023-03-31T02:31:22.920268+08:00",
    "hostname": "m15",
    "dbname": "addb",
    "result": "SUCCESS"
  "fields": {
    "timestamp": [
  "sort": [

The timezone in ES is UTC, how to set it to local time?

Here is my code:

with Elasticsearch(hosts=hosts, timeout=300) as es:
    if not es.indices.exists(index=index_name):

    doc = {
        "timestamp": timestamp,
        "hostname": hostname,
        "dbname": dbname,
        "result": result

    doc_id = "{}-{}-{}".format(dbname, hostname, timestamp)
    es.index(index=index_name, body=doc, id=doc_id)

and the sdk doc:

Elasticsearch only stores data in UTC, you cannot change that and all you can do is store the UTC offset in the timestamp.

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