Sort terms aggregation hits by topHits first hit

Hi,

I'm running the following query:

GET security/_search
{
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"aggBy": {
"terms": {
"field": "assetType",
"size": 250,
"order": {
"_count": "asc"
}
},
"aggs": {
"topHits": {
"top_hits": {
"size": 1,
"sort": [{
"createdAt": {
"order": "desc"
}
}]
}
}
}
}
}
}

This groups all documents by their 'assetType' value, and the topHits picks for each group the document with the most recent 'createdAt' timestamp.
My question is, after these results are obtained, is there a way to sort them by a third field. i.e. sort the terms aggregation result by field of the first result of the inner topHits aggregation

Thanks!

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