I am querying aggregation from elasticsearch like below. There is a date type field timestampUtc in the document which saves the utc time. In the query, I am using an input parameter with an offset like 2022-06-01T00:00:00+10:00 and use calendar_interval to support the different timezone. I believe Elasticsearch converts the time 2022-06-01T00:00:00+10:00 into utc time internally when compare with the value saved in the document.
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"range": {
"timestampUtc": {
"gte": "2022-06-01T00:00:00+10:00",
"lte": "2022-07-05T23:59:59+10:00"
}
}
}
]
}
}
}
},
"aggs": {
"value": {
"date_histogram": {
"field": "timestampUtc",
"calendar_interval": "day"
},
"aggs": {
"amount": {
"sum": {
"field": "amount.value"
}
}
}
}
}
The response from above query is:
"buckets" : [
{
"key_as_string" : "2022-05-31T00:00:00.000Z",
"key" : 1653955200000,
"doc_count" : 897,
"amount" : {
"value" : 4.3873789E7
}
},
{
"key_as_string" : "2022-06-01T00:00:00.000Z",
"key" : 1654041600000,
"doc_count" : 1395,
"amount" : {
"value" : 5.6002755E7
}
},
As you can see that in key_as_string field, it shows utc format which is from the value saved in the db. The question is how I can make the date format in the response same as the one I put in the query.