Aggregation sort


(Akuzhan) #1

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
}
}
}
}
]
}
}
}


(system) #2