Search by field percent

Hi

Suppose, I have such objects in index:

{'name':'John','age':25},
{'name':'Mary','age':27},
{'name':'Jack','age':22}

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?

Hey,

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.

--Alex

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

Hey,

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).

--Alex