# Aggregation sort

**URL:** <https://discuss.elastic.co/t/aggregation-sort/32285>\
**Category:** Elasticsearch\
**Created:** [October 15, 2015, 2:43pm UTC](https://discuss.elastic.co/t/aggregation-sort/32285 "2015-10-15T14:43:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akuzhan](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@akuzhan](https://discuss.elastic.co/u/akuzhan)\
**Post date:** [October 15, 2015, 2:43pm UTC](https://discuss.elastic.co/t/aggregation-sort/32285/1 "2015-10-15T14:43:15Z")

</div>

Hi there,

currently i am using es 1.7. I need to sort categories based on sum of languages but that is not it. I also need to calculate volume of hashtag of language and than do sum based on that. Somehow i need to consider child and grandchild aggregation in order to sort categories. I tried almost everything includind scripted\_metric but no luck so far.

So it needs to be something like this;

order:  
{  
sum(languages sum(volume of hashtags)) :"asc"  
}

I would ask your opinions in this matter. Thanks in advance.

Here is my aggregations;

"aggs": {  
"aggscategory": {  
"terms": {  
"field": "categories.aggregationCategoryName",  
"size": 100  
},  
"aggs": {  
"languageaggregationLanguageName": {  
"reverse\_nested": {},  
"aggs": {  
"aggslanguagename": {  
"terms": {  
"field": "language.aggregationLanguageName",  
"size": 10  
},  
"aggs": {  
"reverseagg": {  
"reverse\_nested": {  
},  
"aggs": {  
"hashTaghashTagName": {  
"nested": {  
"path": "hashTag"  
},  
"aggs": {  
"aggsHashTag": {  
"value\_count": {  
"field": "hashTag.hashTagName"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

here is the some results of my query;

```
{

```

"key": "category1",  
"doc\_count": 2025,  
"languageaggregationLanguageName": {  
"doc\_count": 2025,  
"aggslanguagename": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "English",  
"doc\_count": 1790,  
"reverseagg": {  
"doc\_count": 1790,  
"hashTaghashTagName": {  
"doc\_count": 911,  
"aggsHashTag": {  
"value": 910  
}  
}  
}  
},  
{  
"key": "Russian",  
"doc\_count": 1,  
"reverseagg": {  
"doc\_count": 1,  
"hashTaghashTagName": {  
"doc\_count": 4,  
"aggsHashTag": {  
"value": 2  
}  
}  
}  
}  
]  
}  
}  
},  
{  
"key": "category2",  
"doc\_count": 2008,  
"languageaggregationLanguageName": {  
"doc\_count": 2008,  
"aggslanguagename": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 2,  
"buckets": [  
{  
"key": "English",  
"doc\_count": 1648,  
"reverseagg": {  
"doc\_count": 1648,  
"hashTaghashTagName": {  
"doc\_count": 351,  
"aggsHashTag": {  
"value": 350  
}  
}  
}  
},  
{  
"key": "Indonesian",  
"doc\_count": 144,  
"reverseagg": {  
"doc\_count": 144,  
"hashTaghashTagName": {  
"doc\_count": 74,  
"aggsHashTag": {  
"value": 70  
}  
}  
}  
}  
]  
}  
}  
}

---

<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, 11:44pm UTC](https://discuss.elastic.co/t/aggregation-sort/32285/2 "2017-07-05T23:44:35Z")

</div>

Closed on July 5, 2017, 11:44pm UTC


