# Order of aggregations

**URL:** <https://discuss.elastic.co/t/order-of-aggregations/86904>\
**Category:** Elasticsearch\
**Created:** [May 24, 2017, 6:55am UTC](https://discuss.elastic.co/t/order-of-aggregations/86904 "2017-05-24T06:55:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kirtash](https://avatars.discourse-cdn.com/v4/letter/k/a8b319/32.png) [@Kirtash](https://discuss.elastic.co/u/Kirtash)\
**Post date:** [May 24, 2017, 6:55am UTC](https://discuss.elastic.co/t/order-of-aggregations/86904/1 "2017-05-24T06:55:28Z")

</div>

Hi guys!

Someone can help me to understand the order of aggregations please?

I have this request with these aggregations:

"aggs": {  
"coneixements": {  
"terms": {  
"field": "coneixements.keyword",  
"size": 20,  
"execution\_hint": "global\_ordinals"  
}  
},  
"sexe": {  
"terms": {  
"field": "sexe.keyword",  
"size": 3,  
"execution\_hint": "global\_ordinals"  
}  
},  
"valoracio": {  
"terms": {  
"field": "valoracio.keyword",  
"size": 3,  
"execution\_hint": "global\_ordinals"  
}  
}  
}

But the result is in another order:

"valoracio": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "Normal",  
"doc\_count": 715787  
},  
{  
"key": "Bo",  
"doc\_count": 34542  
},  
{  
"key": "Fluix",  
"doc\_count": 18038  
}  
]  
},  
"coneixements": {  
"doc\_count\_error\_upper\_bound": 5710,  
"sum\_other\_doc\_count": 338545,  
"buckets": [  
{  
"key": "Carnet B1",  
"doc\_count": 277033  
},  
{  
"key": "Carnet Manipulador",  
"doc\_count": 55677  
},  
{  
"key": "Excel",  
"doc\_count": 29867  
},  
{  
"key": "Word",  
"doc\_count": 29552  
},  
{  
"key": "Office",  
"doc\_count": 24318  
},  
{  
"key": "Mecanografia",  
"doc\_count": 23455  
},  
{  
"key": "Comptabilitat",  
"doc\_count": 21786  
},  
{  
"key": "Logística",  
"doc\_count": 11706  
}  
]  
},  
"sexe": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "Home",  
"doc\_count": 430610  
},  
{  
"key": "Dona",  
"doc\_count": 337739  
},  
{  
"key": "Indiferent",  
"doc\_count": 18  
}  
]  
}

Order of request --\> coneixements - sexe - valoracio  
Order of the result --\> valoracio - coneixements - sexe

Thanks!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 24, 2017, 9:03am UTC](https://discuss.elastic.co/t/order-of-aggregations/86904/2 "2017-05-24T09:03:38Z")

</div>

JSON as a standard does not guarantee the order of keys in a map, so we cannot either.

---

<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, 2017, 9:03am UTC](https://discuss.elastic.co/t/order-of-aggregations/86904/3 "2017-06-21T09:03:58Z")

</div>

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