I have a query that finds documents matching selected values in filters, then the result is ordered by my numeric integer field, DESC. The harder part starts with the fact that I need to reduce the result by removing top 15% of the result and 25% worst of the result. I was thinking about doing some bucket script aggregation and calculating the offsets for the field that I sorted with, then using the top hits agg, but I cannot do that as the distribution of the values may not be proportional ie. 70% of all the documents could have the same value.
Adding that I run the queries from JAVA. My current solution is running one query to get the total hits, and then running second query with "size" and "from" calculated with the total from the second one.
Is it even possible to do that with single query given that I cannot use the field I sorted with?
Many thanks in advance and have a nice day.