I want to aggregate data with respect to month and date, I'm trying with date histogram aggregation but its considering full date object.
I have data like:
{
"created" : "2020-09-26",
"id" : 6,
"name" : "Halum khamu"
},
{
"created" : "2021-09-26",
"id" : 7,
"name" : "new new"
},
{
"created" : "2020-10-07",
"id" : 8,
"name" : "Halum new"
}
and I'm using this query:
GET /regulations/_search/
{
"aggs": {
"news_over_time": {
"date_histogram": {
"field": "created",
"calendar_interval": "day",
"keyed": true,
"format": "yyy-MM-dd",
"min_doc_count": 1
}
}
}
}
Its returning data for me:
"buckets" : {
"2020-09-26" : {
"key_as_string" : "2020-09-26",
"key" : 1600300800000,
"doc_count" : 1
},
"2021-09-26" : {
"key_as_string" : "2021-09-26",
"key" : 1601337600000,
"doc_count" : 1
},
"2020-10-07" : {
"key_as_string" : "2020-10-07",
"key" : 1632873600000,
"doc_count" : 1
}
}
But my expected output will be without considering year:
"buckets" : {
"09-26" : {
"key_as_string" : "09-26",
"key" : 1600300800000,
"doc_count" : 2
},
"10-07" : {
"key_as_string" : "10-07",
"key" : 1632873600000,
"doc_count" : 1
}
}
How can I do that?
There's no straightforward way to solve this but this should get the job done:
yielding
EDIT -- There actually is an easier way: