# Are the aggregations in the response of an aggs search query ordered?

**URL:** <https://discuss.elastic.co/t/are-the-aggregations-in-the-response-of-an-aggs-search-query-ordered/273816>\
**Category:** Elasticsearch\
**Created:** [May 24, 2021, 11:31am UTC](https://discuss.elastic.co/t/are-the-aggregations-in-the-response-of-an-aggs-search-query-ordered/273816 "2021-05-24T11:31:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwinbhaskar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashwinbhaskar/32/88750_2.png) [@ashwinbhaskar](https://discuss.elastic.co/u/ashwinbhaskar)\
**Post date:** [May 24, 2021, 11:31am UTC](https://discuss.elastic.co/t/are-the-aggregations-in-the-response-of-an-aggs-search-query-ordered/273816/1 "2021-05-24T11:31:17Z")

</div>

I could not find any explicit statement in the documentation of [data range aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html) that talks about the ordering of the elements inside the `aggregations` field.  
But I noticed that the results are always reverse of the date ranges in the query. Can this be taken as a guarantee of the ordering?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 24, 2021, 11:48am UTC](https://discuss.elastic.co/t/are-the-aggregations-in-the-response-of-an-aggs-search-query-ordered/273816/2 "2021-05-24T11:48:14Z")

</div>

Some have an ordering and some don't. I don't know if the json response from date range is ordered off hand, but I mostly expect folks to use the key to resolve them.

The json spec doesn't attach any iteration order to json objects so we tend to use arrays when the order matters. It's possible for a json parser to jumble the iteration order of objects.

---

<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:** [June 21, 2021, 11:48am UTC](https://discuss.elastic.co/t/are-the-aggregations-in-the-response-of-an-aggs-search-query-ordered/273816/3 "2021-06-21T11:48:17Z")

</div>

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