# Bool Queries and MUST/SHOULD combinations

**URL:** <https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531>\
**Category:** Elasticsearch\
**Created:** [November 1, 2014, 8:39pm UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531 "2014-11-01T20:39:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazoompa\_3](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@kazoompa\_3](https://discuss.elastic.co/u/kazoompa_3)\
**Post date:** [November 1, 2014, 8:39pm UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/1 "2014-11-01T20:39:34Z")

</div>

Hi,

Below is my data and the two queries that I tested, first one failing and  
the latter working. I start to believe that if one wants to combine several  
SHOULD and MUST filters, the outer one must always be SHOULD. Is this a  
correct assumption? In our application, we have much more complex situation  
with several filters within each MUST and SHOULD. And lastly, where should  
place a MUST\_NOT in this case?

Many thanks.

Here is my data:

\_index,\_type,\_id,\_score,\_source.id,\_source.type,\_source.valueType,\_source.sentence,\_source.location  
"test","var","0","1","0","study","text","Lorem text is jumbled","spain"  
"test","var","1","1","1","study","text","bla bla bla","spain"  
"test","var","2","1","2","schema","decimal","ipsum","germany"  
"test","var","3","1","3","study","integer","lorem","france"

Here is my FAILING query:

{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": {  
"terms": {  
"location": [  
"germany"  
]  
}  
},  
"should": {  
"terms": {  
"valueType": [  
"integer"  
]  
}  
}  
}  
}  
}  
}  
}

Here is my WORKING query returning IDs 2 and 3:

{  
"query": {  
"bool": {  
"should": [  
{  
"terms": {  
"location": [  
"germany"  
]  
}  
},  
{  
"bool": {  
"must": [  
{  
"terms": {  
"valueType": [  
"integer"  
]  
}  
}  
]  
}  
}  
]  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 3, 2014, 10:02pm UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/2 "2014-11-03T22:02:06Z")

</div>

Must clauses are queries that must return a document. In the first query,  
any document returned MUST have a location of Germany. The valueType should  
clause is optional and actually pointless as a filter since it does not  
contribute to scoring.

Can you explain what your query should be doing in terms of boolean logic?

--  
Ivan

On Sat, Nov 1, 2014 at 4:39 PM, kazoompa [rhaeri@p3g.org](mailto:rhaeri@p3g.org) wrote:

> Hi,
> 
> Below is my data and the two queries that I tested, first one failing and  
> the latter working. I start to believe that if one wants to combine several  
> SHOULD and MUST filters, the outer one must always be SHOULD. Is this a  
> correct assumption? In our application, we have much more complex situation  
> with several filters within each MUST and SHOULD. And lastly, where should  
> place a MUST\_NOT in this case?
> 
> Many thanks.
> 
> Here is my data:
> 
> \_index,\_type,\_id,\_score,\_source.id,\_source.type,\_source.valueType,\_source.sentence,\_source.location  
> "test","var","0","1","0","study","text","Lorem text is jumbled","spain"  
> "test","var","1","1","1","study","text","bla bla bla","spain"  
> "test","var","2","1","2","schema","decimal","ipsum","germany"  
> "test","var","3","1","3","study","integer","lorem","france"
> 
> Here is my FAILING query:
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "bool": {  
> "must": {  
> "terms": {  
> "location": [  
> "germany"  
> ]  
> }  
> },  
> "should": {  
> "terms": {  
> "valueType": [  
> "integer"  
> ]  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Here is my WORKING query returning IDs 2 and 3:
> 
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "terms": {  
> "location": [  
> "germany"  
> ]  
> }  
> },  
> {  
> "bool": {  
> "must": [  
> {  
> "terms": {  
> "valueType": [  
> "integer"  
> ]  
> }  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCgojLxpzSrYQyW1%3DfeaF\_TJdkx4dqgaxq0\_sijvq6dvw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCgojLxpzSrYQyW1%3DfeaF_TJdkx4dqgaxq0_sijvq6dvw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kazoompa\_3](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@kazoompa\_3](https://discuss.elastic.co/u/kazoompa_3)\
**Post date:** [November 3, 2014, 10:51pm UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/3 "2014-11-03T22:51:43Z")

</div>

Thanks Ivan,

We would like to create complex queries explained in this  
page: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/combining-filters.html#bool-filter).  
I have to admit I don't see why anybody would like to put MUSTs and SHOULDs  
at same level. After further analysis, it seems that if I like to do  
something like:

(For this example conside A, B and, C as terms filters and 'in' implying  
their possible values:)

A in [a1, a2,...] OR B in [b1, b2,...] AND C in [c1, c2. ...] // order is  
important

I have to implement my bool filter as:

{  
"bool": {  
"must": [  
{  
"bool": {  
"should": [  
{  
"terms": {  
"A": [  
"a1",  
"a2"  
]  
}  
},  
{  
"terms": {  
"B": [  
"b1",  
"b2"  
]  
}  
}  
]  
},  
"terms": {  
"C": [  
"c1",  
"c2"  
]  
}  
}  
]  
}  
}

It's sort of a Polish notation for queries 😉

Cheers.

On Monday, November 3, 2014 5:02:15 PM UTC-5, Ivan Brusic wrote:

> Must clauses are queries that must return a document. In the first query,  
> any document returned MUST have a location of Germany. The valueType should  
> clause is optional and actually pointless as a filter since it does not  
> contribute to scoring.
> 
> Can you explain what your query should be doing in terms of boolean logic?
> 
> --  
> Ivan
> 
> On Sat, Nov 1, 2014 at 4:39 PM, kazoompa \<[rha...@p3g.org](mailto:rha...@p3g.org) \<javascript:\>\>  
> wrote:
> 
> > Hi,
> > 
> > Below is my data and the two queries that I tested, first one failing and  
> > the latter working. I start to believe that if one wants to combine several  
> > SHOULD and MUST filters, the outer one must always be SHOULD. Is this a  
> > correct assumption? In our application, we have much more complex situation  
> > with several filters within each MUST and SHOULD. And lastly, where should  
> > place a MUST\_NOT in this case?
> > 
> > Many thanks.
> > 
> > Here is my data:
> > 
> > \_index,\_type,\_id,\_score,\_source.id,\_source.type,\_source.valueType,\_source.sentence,\_source.location  
> > "test","var","0","1","0","study","text","Lorem text is jumbled","spain"  
> > "test","var","1","1","1","study","text","bla bla bla","spain"  
> > "test","var","2","1","2","schema","decimal","ipsum","germany"  
> > "test","var","3","1","3","study","integer","lorem","france"
> > 
> > Here is my FAILING query:
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "bool": {  
> > "must": {  
> > "terms": {  
> > "location": [  
> > "germany"  
> > ]  
> > }  
> > },  
> > "should": {  
> > "terms": {  
> > "valueType": [  
> > "integer"  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > Here is my WORKING query returning IDs 2 and 3:
> > 
> > {  
> > "query": {  
> > "bool": {  
> > "should": [  
> > {  
> > "terms": {  
> > "location": [  
> > "germany"  
> > ]  
> > }  
> > },  
> > {  
> > "bool": {  
> > "must": [  
> > {  
> > "terms": {  
> > "valueType": [  
> > "integer"  
> > ]  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 4, 2014, 4:55pm UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/4 "2014-11-04T16:55:19Z")

</div>

Should clauses at the same time as must clauses are only important during  
queries (not filters) since they contribute to the scoring for a document.  
The should clauses will improve the score for the documents that match.

--  
Ivan

On Mon, Nov 3, 2014 at 5:51 PM, kazoompa [rhaeri@p3g.org](mailto:rhaeri@p3g.org) wrote:

> Thanks Ivan,
> 
> We would like to create complex queries explained in this page:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/combining-filters.html#bool-filter).  
> I have to admit I don't see why anybody would like to put MUSTs and SHOULDs  
> at same level. After further analysis, it seems that if I like to do  
> something like:
> 
> (For this example conside A, B and, C as terms filters and 'in' implying  
> their possible values:)
> 
> A in [a1, a2,...] OR B in [b1, b2,...] AND C in [c1, c2. ...] // order  
> is important
> 
> I have to implement my bool filter as:
> 
> {  
> "bool": {  
> "must": [  
> {  
> "bool": {  
> "should": [  
> {  
> "terms": {  
> "A": [  
> "a1",  
> "a2"  
> ]  
> }  
> },  
> {  
> "terms": {  
> "B": [  
> "b1",  
> "b2"  
> ]  
> }  
> }  
> ]  
> },  
> "terms": {  
> "C": [  
> "c1",  
> "c2"  
> ]  
> }  
> }  
> ]  
> }  
> }
> 
> It's sort of a Polish notation for queries 😉
> 
> Cheers.
> 
> On Monday, November 3, 2014 5:02:15 PM UTC-5, Ivan Brusic wrote:
> 
> > Must clauses are queries that must return a document. In the first query,  
> > any document returned MUST have a location of Germany. The valueType should  
> > clause is optional and actually pointless as a filter since it does not  
> > contribute to scoring.
> > 
> > Can you explain what your query should be doing in terms of boolean logic?
> > 
> > --  
> > Ivan
> > 
> > On Sat, Nov 1, 2014 at 4:39 PM, kazoompa [rha...@p3g.org](mailto:rha...@p3g.org) wrote:
> > 
> > > Hi,
> > > 
> > > Below is my data and the two queries that I tested, first one failing  
> > > and the latter working. I start to believe that if one wants to combine  
> > > several SHOULD and MUST filters, the outer one must always be SHOULD. Is  
> > > this a correct assumption? In our application, we have much more complex  
> > > situation with several filters within each MUST and SHOULD. And lastly,  
> > > where should place a MUST\_NOT in this case?
> > > 
> > > Many thanks.
> > > 
> > > Here is my data:
> > > 
> > > \_index,\_type,\_id,\_score,\_source.id,\_source.type,\_source.valueType,\_source.sentence,\_source.location  
> > > "test","var","0","1","0","study","text","Lorem text is jumbled","spain"  
> > > "test","var","1","1","1","study","text","bla bla bla","spain"  
> > > "test","var","2","1","2","schema","decimal","ipsum","germany"  
> > > "test","var","3","1","3","study","integer","lorem","france"
> > > 
> > > Here is my FAILING query:
> > > 
> > > {  
> > > "query": {  
> > > "filtered": {  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "filter": {  
> > > "bool": {  
> > > "must": {  
> > > "terms": {  
> > > "location": [  
> > > "germany"  
> > > ]  
> > > }  
> > > },  
> > > "should": {  
> > > "terms": {  
> > > "valueType": [  
> > > "integer"  
> > > ]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > Here is my WORKING query returning IDs 2 and 3:
> > > 
> > > {  
> > > "query": {  
> > > "bool": {  
> > > "should": [  
> > > {  
> > > "terms": {  
> > > "location": [  
> > > "germany"  
> > > ]  
> > > }  
> > > },  
> > > {  
> > > "bool": {  
> > > "must": [  
> > > {  
> > > "terms": {  
> > > "valueType": [  
> > > "integer"  
> > > ]  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }  
> > > }
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%  
> > > [40googlegroups.com](http://40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRFfcTDA1Q3S8JKpkECayGoL-qtr2Z9EDrbku\_%3D\_bQMQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRFfcTDA1Q3S8JKpkECayGoL-qtr2Z9EDrbku_%3D_bQMQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kazoompa\_2](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@kazoompa\_2](https://discuss.elastic.co/u/kazoompa_2)\
**Post date:** [November 6, 2014, 2:52am UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/5 "2014-11-06T02:52:50Z")

</div>

Thanks Ivan,

We finally opted for building our queries (thru a UI query builder) in a  
nested fashion as dscribed above, it seems to serve our need.

Cheers for the info though.

On Tuesday, November 4, 2014 11:55:27 AM UTC-5, Ivan Brusic wrote:

> Should clauses at the same time as must clauses are only important during  
> queries (not filters) since they contribute to the scoring for a document.  
> The should clauses will improve the score for the documents that match.
> 
> --  
> Ivan
> 
> On Mon, Nov 3, 2014 at 5:51 PM, kazoompa \<[rha...@p3g.org](mailto:rha...@p3g.org) \<javascript:\>\>  
> wrote:
> 
> > Thanks Ivan,
> > 
> > We would like to create complex queries explained in this page:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/combining-filters.html#bool-filter).  
> > I have to admit I don't see why anybody would like to put MUSTs and SHOULDs  
> > at same level. After further analysis, it seems that if I like to do  
> > something like:
> > 
> > (For this example conside A, B and, C as terms filters and 'in' implying  
> > their possible values:)
> > 
> > A in [a1, a2,...] OR B in [b1, b2,...] AND C in [c1, c2. ...] // order  
> > is important
> > 
> > I have to implement my bool filter as:
> > 
> > {  
> > "bool": {  
> > "must": [  
> > {  
> > "bool": {  
> > "should": [  
> > {  
> > "terms": {  
> > "A": [  
> > "a1",  
> > "a2"  
> > ]  
> > }  
> > },  
> > {  
> > "terms": {  
> > "B": [  
> > "b1",  
> > "b2"  
> > ]  
> > }  
> > }  
> > ]  
> > },  
> > "terms": {  
> > "C": [  
> > "c1",  
> > "c2"  
> > ]  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > It's sort of a Polish notation for queries 😉
> > 
> > Cheers.
> > 
> > On Monday, November 3, 2014 5:02:15 PM UTC-5, Ivan Brusic wrote:
> > 
> > > Must clauses are queries that must return a document. In the first  
> > > query, any document returned MUST have a location of Germany. The valueType  
> > > should clause is optional and actually pointless as a filter since it does  
> > > not contribute to scoring.
> > > 
> > > Can you explain what your query should be doing in terms of boolean  
> > > logic?
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Sat, Nov 1, 2014 at 4:39 PM, kazoompa [rha...@p3g.org](mailto:rha...@p3g.org) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Below is my data and the two queries that I tested, first one failing  
> > > > and the latter working. I start to believe that if one wants to combine  
> > > > several SHOULD and MUST filters, the outer one must always be SHOULD. Is  
> > > > this a correct assumption? In our application, we have much more complex  
> > > > situation with several filters within each MUST and SHOULD. And lastly,  
> > > > where should place a MUST\_NOT in this case?
> > > > 
> > > > Many thanks.
> > > > 
> > > > Here is my data:
> > > > 
> > > > \_index,\_type,\_id,\_score,\_source.id,\_source.type,\_source.valueType,\_source.sentence,\_source.location  
> > > > "test","var","0","1","0","study","text","Lorem text is jumbled","spain"  
> > > > "test","var","1","1","1","study","text","bla bla bla","spain"  
> > > > "test","var","2","1","2","schema","decimal","ipsum","germany"  
> > > > "test","var","3","1","3","study","integer","lorem","france"
> > > > 
> > > > Here is my FAILING query:
> > > > 
> > > > {  
> > > > "query": {  
> > > > "filtered": {  
> > > > "query": {  
> > > > "match\_all": {}  
> > > > },  
> > > > "filter": {  
> > > > "bool": {  
> > > > "must": {  
> > > > "terms": {  
> > > > "location": [  
> > > > "germany"  
> > > > ]  
> > > > }  
> > > > },  
> > > > "should": {  
> > > > "terms": {  
> > > > "valueType": [  
> > > > "integer"  
> > > > ]  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > Here is my WORKING query returning IDs 2 and 3:
> > > > 
> > > > {  
> > > > "query": {  
> > > > "bool": {  
> > > > "should": [  
> > > > {  
> > > > "terms": {  
> > > > "location": [  
> > > > "germany"  
> > > > ]  
> > > > }  
> > > > },  
> > > > {  
> > > > "bool": {  
> > > > "must": [  
> > > > {  
> > > > "terms": {  
> > > > "valueType": [  
> > > > "integer"  
> > > > ]  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d4597d15-8785-4e97-9c3f-8be9aacddf9b%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a33a6974-4a95-4632-9c56-bea3d19ce7f0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0be6e810-9b08-47b0-b071-93b601c48626%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0be6e810-9b08-47b0-b071-93b601c48626%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:51am UTC](https://discuss.elastic.co/t/bool-queries-and-must-should-combinations/20531/6 "2017-07-06T00:51:57Z")

</div>


