We have some Elasticsearch queries that take the following form:
{
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "content",
"query": "Lorem ipsum dolor sit amet"
}
},
{
"query_string": {
"default_field": "content",
"query": "Nunc ac auctor massa"
}
}
]
}
}
}
We'd like to surface the hit counts on each boolean clause. Our current brute force approach has been to execute a secondary multi-search under the covers, splitting each clause into its own separate query to get the individual counts. This can get very expensive as we support up to 50 of these clauses which can potentially result into another 50 queries executed behind the scenes.
We've looked for alternative ways to extract counts such as Get matched terms from Lucene query or lucene get matched terms in query but all of them involve bean counting the actual hits. This is prohibitive as we can potentially have thousands of them.
Is there another more efficient approach/technique (preferably in Elasticsearch) for getting those counts that we might have missed?