Hi all,
I would like to sort a list of nested aggregations by their document count (and not terms count). This can be done using a reverse nested aggregation.
More than a year ago I've asked this question on the old mailing list, see here Reverse Nested Aggregation Sort.
There never came an answer. Perhaps new insights can be gained now.
Assume I have as example this response (snippet) for a reverse nested aggregation:
"aggregations": {
"values": {
"doc_count": 350627,
"values_filter": {
"doc_count": 79325,
"values": {
"doc_count_error_upper_bound": 153,
"sum_other_doc_count": 33654,
"buckets": [
{
"key": "Alpha",
"doc_count": 395,
"values_docCount": {
"doc_count": 381
}
},
{
"key": "Beta",
"doc_count": 366,
"values_docCount": {
"doc_count": 352
}
},
{
"key": "Gamma",
"doc_count": 335,
"values_docCount": {
"doc_count": 331
}
},
What is the best way to sort this list in Elasticsearch based on the "values_docCount.doc_count"? Is script-based sorting the recommended approach?