# Max Bucket across multiple days

**URL:** https://discuss.elastic.co/t/max-bucket-across-multiple-days/128300
**Category:** Elasticsearch
**Created:** [April 17, 2018, 7:13am UTC](https://discuss.elastic.co/t/max-bucket-across-multiple-days/128300 "2018-04-17T07:13:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ysl](https://avatars.discourse-cdn.com/v4/letter/y/4af34b/32.png) [@ysl](https://discuss.elastic.co/u/ysl)
#### Post date: [April 17, 2018, 7:13am UTC](https://discuss.elastic.co/t/max-bucket-across-multiple-days/128300/1 "2018-04-17T07:13:14Z")

</div>

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"  
]  
}

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 15, 2018, 7:13am UTC](https://discuss.elastic.co/t/max-bucket-across-multiple-days/128300/2 "2018-05-15T07:13:34Z")

</div>

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