Filter with multiple should and minimum_should_match


(Vladimir) #1

Assume I need to filter result with documents where one string field, 'roles', in "Role1" OR another string field, 'groups', is "Group1"

GET /_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "Alex"
          }
        }
      ],
      "filter": [
        {
          "bool": {
            "should": [
              {
                "terms": {
                  "roles": [
                    "Role1"
                  ]
                }
              },
              {
                "terms": {
                  "groups": [
                    "Group1"
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Do I need to use "minimum_should_match": 1 if at least one should with Role1 or should with Group1 be found?
When parameter "minimum_should_match" is required in such type of filters ?


#2

When you are putting the filter at outer query level(With only should in inner level query), then you don't need the minimum_should_match at inner level unless you are putting must/filter/MUST_NOT at inner level also. Because filter means MUST_WITH_CONSTANT/NO score, so your inner level query has to match atleast 1 clause.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.