I want to write an aggregation which returns the percentage of hits for any query
Let say I have a query Q which returns me 20 docs out of the 100 present in the target index.
Then that aggregation should return me 20% when I add the query to it.
I should clarify that I am using a span_near query which works fine, but I want to know how many hits it gets in percentage and it really shouldn't be this hard to figure out.
I found this question which discusses a similar use-case which is getting the percentage of success. However, they have used term filter and I need span_near which is not available under filters but only under query.
I also came across this question, the solution which describes my use case exactly. Unfortunately it does not have an answer.
I notice you've set size to 0, so I'm assuming you don't care about the actual hits. If you do, you can add a top_hits aggregation to the matching_docsfilter agg.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.