Minimum must match filtered query

Is it possible to have such a request

"query": { "filtered": { "filter": { "terms": { "names": [ "Anna", "Mark", "Joe" ], "execution" : "and" } } } } 

Using the instruction "minimum_should_match": "2" ?

I know that I can use a simple query (I tried, it works), but I do not need to calculate the score. My goal is to simply filter documents containing 2 values.

Does the assessment as a whole greatly affect the time required to receive the document?

Using this query:

  "query": { "filtered": { "filter": { "terms": { "names": [ "Anna", "Mark", "Joe" ], "execution" : "and", "minimum_should_match": "2" } } } } 

I got this error:

 QueryParsingException[[my_db] [terms] filter does not support [minimum_should_match]] 
+5
source share
1 answer

Minimum match is not a parameter for terms filter . If this is the functionality you are looking for, I can rewrite your query as follows to use the bool query wrapped in a query filter :

 { "filter": { "query": { "bool": { "must": [ { "term": { "names": "Anna" } }, { "term": { "names": "Mark" } }, { "term": { "name": "Joe" } } ], "minimum_number_should_match": 2 } } } } 

You will receive documents matching preferably exactly all three, but the request will also match the document with exactly two of the three terms. must is implicit and. We also do not calculate the score, since we executed the query as a filter.

+3
source

Source: https://habr.com/ru/post/1232459/


All Articles