How to get the hour with the highest value for each day instead of highest value across multiple day?
In the below script the returned result is the max bucket of 1 hour interval across days. I would like to have each single day with the max bucket of that certain hour.
GET test/_search
{
"size": 0,
"query": {
"bool": {
"filter": [
{ "match": { "category": "subset" } }
]
}
},
"aggs" : {
"per_hour" : {
"date_histogram" : {
"field" : "timestamp",
"interval" : "60m"
},
"aggs": {
"sales": {
"sum": {
"field": "total_sales"
}
}
}
},
"max_monthly_sales": {
"max_bucket": {
"buckets_path": "per_hour>sales"
}
}
}
}
The output I want:
"max_monthly_sales": {
"value": 3771,
"keys": [
"2018-04-11T02:00:00.000Z"
]
}
"max_monthly_sales": {
"value": 3771,
"keys": [
"2018-04-12T09:00:00.000Z"
]
}
"max_monthly_sales": {
"value": 3601,
"keys": [
"2018-04-13T02:00:00.000Z"
]
}
"max_monthly_sales": {
"value": 3771,
"keys": [
"2018-04-14T08:00:00.000Z"
]
}