To get end date of week in date histogram

Hi Team,

I am using date_histogram type of aggregation for aggregating month level data and interval as Week(1w). Now, In the response 'key' value comes as start date of the week. But I would like to get end date of the week in 'key'. Could you please help.

eg.,
The aggregation query I am using,

"aggs": {
"Weekly_Counts": {
"date_histogram": {
"field": "created",
"interval": "1w",
"format":"yyyy-MM-dd E",
"time_zone":"Asia/Calcutta",
"min_doc_count": 1
}
}
}

the output i am getting like below. In 'key; the time is of start date of the week. Instead I would like to get end date of the week. Would you please help.

{
....
"aggregations": {
"Weekly_Counts": {
"buckets": [
{
"key_as_string": "2018-01-01 Mon",
"key": 1514745000000,
"doc_count": 7672
},
{
"key_as_string": "2018-01-08 Mon",
"key": 1515349800000,
"doc_count": 7754
},
{
"key_as_string": "2018-01-15 Mon",
"key": 1515954600000,
"doc_count": 7643
}
]
}
}
}

Expectation:

In key, I would like to get the end date of the week as "2018-01-07 Sun"

This feature isn't supported unfortunately.

Thank you jpountz. In following with your answer, having another doubt. shall I able to get the start date and end date in key like
"key_as_string": "2018-01-15 - 2018-01-21".

We know in date range its possible. But there the limitation is we need to specify range for every bucket.

I opened https://github.com/elastic/elasticsearch/issues/28479 to discuss it.

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