M4cJunk13
M4cJunk13

Reputation: 429

In Elasticsearch, is there a way to get hits.total.value for each query in a compound query?

If I have a compound query like the example below, would it be possible to get the total hits value per query instead of just the hits.total.value for the entire query as a whole?

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "johann sebastian bach"
          }
        },
        {
          "match_phrase": {
            "name": "johann sebastian bach"
          }
        },
        {
          "match": {
            "name": {
              "query": "johann sebastian bach",
              "minimum_should_match": "2<75%"
            }
          }
        }
      ]
    }
  }
}

Upvotes: 0

Views: 573

Answers (1)

Val
Val

Reputation: 217464

Not with a single query, but since your query is simple you could send each separately to the _msearch endpoint and get the count for each.

POST your-index/_msearch
{ }
{"query" : {"match" : { "name": "johann sebastian bach"}}}
{ }
{"query" : {"match" : { "name": "johann sebastian bach"}}}
{ }
{"query" : {"match" : { "name": {"query": "johann sebastian bach", "minimum_should_match": "2<75%"}}}}

In the response, you'll get hits.total.value for each query.

Upvotes: 1

Related Questions