Post filter to grasp only a % of items in the primary results set?


For QC purpose, my users want to randomly select a % of found documents of the a query they built within elasticsearch.
I was think of using Post filter feature with a script that does random fetching.
Is it the correct approach ?
I don't find any pointer in the documentation about that .


I saw native scripting as well,
Not clear to me the invocation stack of this class/object as I will use "global" variables.
Can I hook the first execution of that script in a filter scope ?

Honestly, I think this is something best accomplished in your application code. You could use something like a script query in the post_filter which randomly includes/excludes documents, but this won't be terribly efficient since it will traverse over all of the matching results.

E.g. if your query matches 1000 documents, but you only ask for the top-10 results, the post_filter will still run over all 1000 docs.

This is easily handled in your application code though. Just ask for n documents and randomly filter out some of them.