TimeZone issue in GET API

Hi,
I am facing a challenge in displaying the dateTime field in local time zone.

When I filter the data in kibana 'Discover' I am getting the date and time in local time zone.
But when I query using the GET API in dev tools, I am not getting the results in local time zone but in UTC.

Below is the API I am running to fetch the data from 2020-08-25T00:00:00 to 2020-08-26T00:00:00.
`````````````````````````````````````````````````````````````````````
GET systemload-log/_search
{
"size": 10000,
"aggs": {
"range": {
"date_range": {
"field": "generateTime_readable",
"time_zone":"Asia/Calcutta",
"ranges": [
{
"from":"2020-08-25T00:00:00.000Z",
"to":"2020-08-26T00:00:00.000Z"
}
]
}
}
}
}


Below is the first hit and the generateTime_readable value is 2020-08-25T14:40:00.000Z.
The records from 2020-08-25T00:00:00 to 2020-08-25T14:39:00 are missing though it exists.

`````````````````````````````````````````````
    "hits" : [
          {
            "_index" : "systemload-log",
            "_type" : "_doc",
            "_id" : "aJcPJnQBBTV2xJn45Ksl",
            "_score" : 1.0,
            "_source" : {
              "host" : "xxx"
              "memLoad" : "23",
              "message" : "hidden",
              "tenantId" : "2",
              "diskLoad" : "6",
              "port" : 56514,
              "timestamp" : "2020-08-25T14:39:49+0000",
              "Type" : "systemLoadLog",
              "vsnId" : "0",
              "cpuLoad" : "0",
              "sessLoad" : "135",
              "@timestamp" : "2020-08-25T14:40:09.617Z",
              "applianceName" : "xxxx",
              "@version" : "1",
              "generateTime_readable" : **"2020-08-25T14:40:00.000Z"**,
              "tenantName" : "test",
              "applianceId" : "0",
              "generateTime" : "1598366400"
            }
          },`
    ````````````````````````````````````````````````````````````````
Please help me to show the results in local time zone.

Hello @subash

Discover converts time fields in documents to the local time. If you are consuming a raw api request then you must perform the conversion yourself.

1 Like

This is a bit of a UX break in my opinion, I've created https://github.com/elastic/kibana/issues/76050 to see what we can do here :slight_smile:

I have given "time_zone":"Asia/Calcutta" in the API but still getting the results in UTC.
I am not sure whether it is the correct way of doing.

Please suggest, how to do the time_zone conversion in API.

time_zone is used as an argument for the date range aggregation and is not used to format the resulting document. Relevant docs - Date range aggregation | Elasticsearch Guide [8.11] | Elastic

Please suggest, how to do the time_zone conversion in API.

This isn't possible. You would need to covert the value with whatever code is consuming the API response.

2 Likes

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