# Filter makes should query invalid

**URL:** <https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869>\
**Category:** Elasticsearch\
**Created:** [June 19, 2017, 1:31am UTC](https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869 "2017-06-19T01:31:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziiloz](https://avatars.discourse-cdn.com/v4/letter/z/aca169/32.png) [@ziiloz](https://discuss.elastic.co/u/ziiloz)\
**Post date:** [June 19, 2017, 1:31am UTC](https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869/1 "2017-06-19T01:31:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Georg\_Brandemann](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@Georg\_Brandemann](https://discuss.elastic.co/u/Georg_Brandemann)\
**Post date:** [June 19, 2017, 10:14am UTC](https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869/2 "2017-06-19T10:14:04Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ziiloz](https://avatars.discourse-cdn.com/v4/letter/z/aca169/32.png) [@ziiloz](https://discuss.elastic.co/u/ziiloz)\
**Post date:** [June 20, 2017, 3:10am UTC](https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869/3 "2017-06-20T03:10:08Z")

</div>

> [@Georg\_Brandemann](#):
>
> Georg

thanks Georg, it helps a lot

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 18, 2017, 3:10am UTC](https://discuss.elastic.co/t/filter-makes-should-query-invalid/89869/4 "2017-07-18T03:10:26Z")

</div>

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