# Order results of date Histogram

**URL:** <https://discuss.elastic.co/t/order-results-of-date-histogram/141591>\
**Category:** Elasticsearch\
**Created:** [July 25, 2018, 1:52pm UTC](https://discuss.elastic.co/t/order-results-of-date-histogram/141591 "2018-07-25T13:52:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisHck](https://avatars.discourse-cdn.com/v4/letter/c/e47c2d/32.png) [@ChrisHck](https://discuss.elastic.co/u/ChrisHck)\
**Post date:** [July 25, 2018, 1:52pm UTC](https://discuss.elastic.co/t/order-results-of-date-histogram/141591/1 "2018-07-25T13:52:30Z")

</div>

Hello, is it possible to order the hourly aggregated **values** (results of a date histogram aggregation)? I wish to order the results based on the value instead of the date.

I think that I can not use a histogram aggregation because I still need the hourly/daily aggregation before I can order the values. To do so, I am trying this :  
{  
"query": {  
....  
},  
"aggs": {  
"datas": {  
"date\_histogram": {  
"field": "@timestamp",  
"interval": "1h"  
},  
"aggs": {  
"OrderedValue":{  
"terms":{"field":"value","order":{"ValueToOrder":"asc"}},  
"aggs":{  
"ValueToOrder": {"avg":{"field":"value"}  
}  
}  
}  
}  
}  
}  
}

However, with this code, I can only order the values before the hourly aggregation...  
And here is the format of my data  
{  
"\_index": "metric-005215Troi",  
"\_type": "measured",  
"\_id": "005215Troi",  
"\_score": 4.3412647,  
"\_source": {  
"name": "005215\_Troi",  
"@timestamp": "2017-09-23 23:00:00",  
"value": 15.9  
}  
}

Can someone explain me how I can sort the results of a date histogram (ascending order of the value measured instead of the timestamp)

---

<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:** [August 22, 2018, 1:52pm UTC](https://discuss.elastic.co/t/order-results-of-date-histogram/141591/2 "2018-08-22T13:52:34Z")

</div>

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