Search by field percent


Suppose, I have such objects in index:


How to search objects with age > 90% of max age?

Percentage for John is 25100/27=92, for jack is 22100/27=81, for Mary is 100. So, 90% filter must select Mary and John, but it must pass Jack.

What is the best way to implement such search logic?


how about: First execute an aggregation to get the max value, then calculate the 90% out of that (to get the absolute value, might work with some scripting as well), and use this absolute value in a second query.


Already done, but I was searching for solution with one request (maybe with some groovy scripting on server side)


no, the execution order of search and aggregation is opposite as needed for your use-case (as the aggregations built in the search results and you need the search results built on top the aggs result - which would require more roundtrips).