Hi
I wish to be able to sort my buckets from a termAggregation, based on the scores of the top N documents in each bucket.
I know how to sort by min/max/avg/sum score for all documents in a bucket (See example I further down), but I wish to sort by avg/sum of only top N documents in each bucket.
I have tried to used topHits aggregation, but can get it working, since it is not a bucketAggregation, and thus I can not make nested aggregations with it.
Will appreciate any help, guiding me in a direction of doing this.
Thanks
Jens
{
"size": 0,
"query": {
"nested": {
"path": "<somePath>",
"query": {
"term": {
"<someField>": {
"value": "1808439"
}
}
}
}
},
"aggs": {
"agg_name": {
"terms": {
"field": "<someField>",
"order": {
"sum_score": "desc"
},
"size": "3"
},
"aggs": {
"sum_score": {
"sum": {
"script": "_score"
}
}
}
}
}
}