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.
here is my working span_near query -
GET /transform_test6_4/_search?size=0
{
"query": {
"span_near": {
"clauses": [
{
"span_term": {
"eventFlow": "click_input"
}
},
{
"span_term": {
"eventFlow": "idle"
}
}
],
"slop": 120,
"in_order": true
}
}
}