# Range Aggregations: response bucket order?

**URL:** <https://discuss.elastic.co/t/range-aggregations-response-bucket-order/19888>\
**Category:** Elasticsearch\
**Created:** [September 19, 2014, 5:47pm UTC](https://discuss.elastic.co/t/range-aggregations-response-bucket-order/19888 "2014-09-19T17:47:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Addison](https://avatars.discourse-cdn.com/v4/letter/j/b2d939/32.png) [@James\_Addison](https://discuss.elastic.co/u/James_Addison)\
**Post date:** [September 19, 2014, 5:47pm UTC](https://discuss.elastic.co/t/range-aggregations-response-bucket-order/19888/1 "2014-09-19T17:47:21Z")

</div>

I would have thought that range aggregations return the bucket list in the  
order the range agg is listed, but I'm not seeing that result. (ES 1.3.2)  
Is there a way to enforce original ordering that I'm missing?  
My range aggregation:

"day\_of\_week\_range": {  
"range": {  
"field": "sessions.events.days\_of\_week",  
"ranges": [  
{"from":0, "to":5, "key": "Weekdays"},  
{"from":5, "to":7, "key": "Weekends"},  
{"from":6, "to":6, "key": "Sunday"},  
{"from":0, "to":1, "key": "Monday"},  
{"from":1, "to":2, "key": "Tuesday"},  
{"from":2, "to":3, "key": "Wednesday"},  
{"from":3, "to":4, "key": "Thursday"},  
{"from":4, "to":5, "key": "Friday"},  
{"from":5, "to":6, "key": "Saturday"}  
]  
}  
}

And the response (Note that Weekdays is 2nd in the response, which is why  
I'm posting):

"day\_of\_week\_range": {  
"buckets": [  
{  
"key": "Monday",  
"from": 0,  
"from\_as\_string": "0.0",  
"to": 1,  
"to\_as\_string": "1.0",  
"doc\_count": 11  
},  
{  
"key": "Weekdays",  
"from": 0,  
"from\_as\_string": "0.0",  
"to": 5,  
"to\_as\_string": "5.0",  
"doc\_count": 40  
},  
{  
"key": "Tuesday",  
"from": 1,  
"from\_as\_string": "1.0",  
"to": 2,  
"to\_as\_string": "2.0",  
"doc\_count": 11  
},  
{  
"key": "Wednesday",  
"from": 2,  
"from\_as\_string": "2.0",  
"to": 3,  
"to\_as\_string": "3.0",  
"doc\_count": 10  
},  
{  
"key": "Thursday",  
"from": 3,  
"from\_as\_string": "3.0",  
"to": 4,  
"to\_as\_string": "4.0",  
"doc\_count": 17  
},  
{  
"key": "Friday",  
"from": 4,  
"from\_as\_string": "4.0",  
"to": 5,  
"to\_as\_string": "5.0",  
"doc\_count": 15  
},  
{  
"key": "Saturday",  
"from": 5,  
"from\_as\_string": "5.0",  
"to": 6,  
"to\_as\_string": "6.0",  
"doc\_count": 28  
},  
{  
"key": "Weekends",  
"from": 5,  
"from\_as\_string": "5.0",  
"to": 7,  
"to\_as\_string": "7.0",  
"doc\_count": 37  
},  
{  
"key": "Sunday",  
"from": 6,  
"from\_as\_string": "6.0",  
"to": 6,  
"to\_as\_string": "6.0",  
"doc\_count": 0  
}  
]  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9a245439-0fd8-4dd3-888b-43ec882c0e16%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9a245439-0fd8-4dd3-888b-43ec882c0e16%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:01am UTC](https://discuss.elastic.co/t/range-aggregations-response-bucket-order/19888/2 "2017-07-06T01:01:02Z")

</div>


