Filter makes should query invalid

hi there,
I have this query which works properly:

{
   "query":{
      "bool":{
         "should":[
            {
               "match":{
                  "Name":"calla"
               }
            }
         ]
      }
   }
}

but when I add a filter to it:

{
   "query":{
      "bool":{
         "filter":{
            "bool":{
               "must_not":[
                  {
                     "term":{
                        "tid":"CALLID1"
                     }
                  }
               ]
            }
         },
         "should":[
            {
               "match":{
                  "Name":"calla"
               }
            }
         ]
      }
   }
}

it returns everything, looks like to me that the should query acts like a match_all. It works fine if I change from should to must. So is it what I should expect or is it a bug

If you combine must/must_not conditions with should you have to use minimum_should_match ( https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html )

From the BoolQuery Doc:
should

The clause (query) should appear in the matching document. If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score. If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter.

Hope that helps,
Georg

thanks Georg, it helps a lot

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