# Better to use "must" and "terms", or "should", in a bool query?

**URL:** <https://discuss.elastic.co/t/better-to-use-must-and-terms-or-should-in-a-bool-query/15200>\
**Category:** Elasticsearch\
**Created:** [January 10, 2014, 4:17pm UTC](https://discuss.elastic.co/t/better-to-use-must-and-terms-or-should-in-a-bool-query/15200 "2014-01-10T16:17:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [January 10, 2014, 4:17pm UTC](https://discuss.elastic.co/t/better-to-use-must-and-terms-or-should-in-a-bool-query/15200/1 "2014-01-10T16:17:57Z")

</div>

Hi guys. These 2 queries produce the same results via different approaches.  
Is there any reason why one should be used over another?

Thanks,  
Nick

{  
"size": 10,  
"fields": ["id", "name"],  
"sort": [{ "name.orig": "asc" }],  
"query": {  
"bool": {  
"must": [  
{  
"terms": {  
"catalog\_ids": ["4dddd736349c302bd100004e", "511a70be63051f6a64000217"],  
"minimum\_should\_match": 1  
}  
}  
]  
}  
}  
}

{  
"size": 10,  
"fields": ["id", "name"],  
"sort": [{ "name.orig": "asc" }],  
"query": {  
"bool": {  
"minimum\_should\_match": 1,  
"should": [  
{ "term": { "catalog\_ids": "4dddd736349c302bd100004e" } },  
{ "term": { "catalog\_ids": "511a70be63051f6a64000217" } }  
]  
}  
}  
}

--  
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/5df1fbf3-9c3a-4f1d-aef0-f7cbec83913d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5df1fbf3-9c3a-4f1d-aef0-f7cbec83913d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 12:01pm UTC](https://discuss.elastic.co/t/better-to-use-must-and-terms-or-should-in-a-bool-query/15200/2 "2014-11-03T12:01:20Z")

</div>

You will only see the difference when you have more complex queries that  
combine MUST and SHOULD together. In your example you could have just  
change MUST to SHOULD (i.e. used TERMS). By the definition, SHOULD is like  
an OR and without a MUST clause it implies 'at least' one should match.

R

On Friday, January 10, 2014 11:17:57 AM UTC-5, Nick Hoffman wrote:

> Hi guys. These 2 queries produce the same results via different  
> approaches. Is there any reason why one should be used over another?
> 
> Thanks,  
> Nick
> 
> {  
> "size": 10,  
> "fields": ["id", "name"],  
> "sort": [{ "name.orig": "asc" }],  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "terms": {  
> "catalog\_ids": ["4dddd736349c302bd100004e", "511a70be63051f6a64000217"],  
> "minimum\_should\_match": 1  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> {  
> "size": 10,  
> "fields": ["id", "name"],  
> "sort": [{ "name.orig": "asc" }],  
> "query": {  
> "bool": {  
> "minimum\_should\_match": 1,  
> "should": [  
> { "term": { "catalog\_ids": "4dddd736349c302bd100004e" } },  
> { "term": { "catalog\_ids": "511a70be63051f6a64000217" } }  
> ]  
> }  
> }  
> }

--  
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/c8973ae2-2b7c-44d1-99f3-5c587acbdc51%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c8973ae2-2b7c-44d1-99f3-5c587acbdc51%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:52am UTC](https://discuss.elastic.co/t/better-to-use-must-and-terms-or-should-in-a-bool-query/15200/3 "2017-07-06T00:52:31Z")

</div>


