# Aggregation sort by timestamp

**URL:** <https://discuss.elastic.co/t/aggregation-sort-by-timestamp/49392>\
**Category:** Elasticsearch\
**Created:** [May 6, 2016, 10:00am UTC](https://discuss.elastic.co/t/aggregation-sort-by-timestamp/49392 "2016-05-06T10:00:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maher](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@maher](https://discuss.elastic.co/u/maher)\
**Post date:** [May 6, 2016, 10:00am UTC](https://discuss.elastic.co/t/aggregation-sort-by-timestamp/49392/1 "2016-05-06T10:00:03Z")

</div>

Hi, I am trying to make a sort by timestamp.

{  
"sort" :[{"timestamp":{"order":"asc"}}],  
"size":0,  
"aggs":{  
"people":{  
"terms":  
{"field":"B2Bunit"},  
"aggs": {  
"products": {  
"terms": {  
"field": "code"  
}  
}  
}  
}  
}  
}  
the problem is that the aggregation force a new sort by doc\_count.  
and if i want to use the order option in the aggregation, the timestamp field is not recognized.

the field timestamp belongs the main document.

Thank you!

---

<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:** [July 5, 2017, 10:53pm UTC](https://discuss.elastic.co/t/aggregation-sort-by-timestamp/49392/2 "2017-07-05T22:53:23Z")

</div>


