# Strange result where a filter query contains a should clause

**URL:** <https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091>\
**Category:** Elasticsearch\
**Created:** [November 5, 2016, 8:59am UTC](https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091 "2016-11-05T08:59:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ginger](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@ginger](https://discuss.elastic.co/u/ginger)\
**Post date:** [November 5, 2016, 8:59am UTC](https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091/1 "2016-11-05T08:59:14Z")

</div>

Hi.  
When learning DSL, I have the following scene.

First, my mapping like this:

> PUT /gb  
> {  
> "mappings": {  
> "tweet" : {  
> "properties" : {  
> "tweet" : {  
> "type" : "string",  
> "analyzer": "english"  
> },  
> "date" : {  
> "type" : "date"  
> }  
> }  
> }  
> }  
> }

Then, I put three documents:

> PUT /gb/tweet/1  
> {  
> "tweet": "my first tweet",  
> "date": "2016-01-01"  
> }  
> PUT /gb/tweet/2  
> {  
> "tweet": "my second tweet",  
> "date": "2016-01-02"  
> }  
> PUT /gb/tweet/3  
> {  
> "tweet": "my third tweet",  
> "date": "2016-01-03"  
> }

Finally, I use the following two querys to search my data:

> GET /gb/tweet/\_search  
> {  
> "query": {  
> "bool": {  
> "must": {"match": {"tweet": "my tweet"}},  
> "should": {"match": {"tweet": "first"}}  
> }  
> }  
> }

> GET /gb/tweet/\_search  
> {  
> "query": {  
> "bool": {  
> "filter": {  
> "bool": {  
> "must": {"match": {"tweet": "my tweet"}},  
> "should": {"match": {"tweet": "first"}}  
> }  
> }  
> }  
> }  
> }  
> only return the first document

The first query returns all three documents, while the second query only returns the first query.  
what's the difference between the two query?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 7, 2016, 9:35am UTC](https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091/2 "2016-11-07T09:35:51Z")

</div>

Hey,

see the [bool filter docs](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-bool-query.html#_scoring_with_literal_bool_filter_literal), stating

> If this query is used in a filter context and it has should clauses then at least one should clause is required to match.

So, in the last example, should is actually becoming a must clause (because there is only a single clause).

Hope this makes sense!

--Alex

---

<div class="post-metadata">

**Author:** ![ginger](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@ginger](https://discuss.elastic.co/u/ginger)\
**Post date:** [November 8, 2016, 4:44am UTC](https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091/3 "2016-11-08T04:44:08Z")

</div>

Thanks!

---

<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:** [December 6, 2016, 4:44am UTC](https://discuss.elastic.co/t/strange-result-where-a-filter-query-contains-a-should-clause/65091/4 "2016-12-06T04:44:15Z")

</div>

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