How to sort based on sum of multiple field value counts

Hi, I have a use case for sorting documents based on the sum of counts of values for an specific field, lets say i have a field rating, and the search query gives 20 docs with rating:High, and 30 with rating:Critical, for a total of 50, then i have 10 with rating:High and 5 with rating:Critical, for a total of 15, the one with sum of 50 would go first and the one with sum 15 will go next if sort descending, i want to be able to sort search results using the sum of these value counts and do it ascending and descending depending on these counts.

Thanks

Elasticsearch have script sorting for if you have to do complex work with the document to produce some value on which to sort. If that is what you are doing then I'd go for that.

I can't 100% tell what you are asking for though so script sorting may not be what you are after.

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