# Bool Query, multiple musts and json legality

**URL:** https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907
**Category:** Elasticsearch
**Created:** [July 23, 2013, 4:44pm UTC](https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907 "2013-07-23T16:44:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Gaydenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_gaydenko/32/914_2.png) [@Andrew\_Gaydenko](https://discuss.elastic.co/u/Andrew_Gaydenko)
#### Post date: [July 23, 2013, 4:44pm UTC](https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907/1 "2013-07-23T16:44:11Z")

</div>

[json.org](http://json.org) doesn't prevent from using the same name key in the same sequence  
of (key, value) pairs. So I have tried (in sense) multiple musts

{  
"query": {  
"bool": {  
"must": {  
"term": { "someFlag": true }  
},  
"must": {  
"range" : {  
"someNumber" : {  
"from" : 50000,  
"to" : 2000000  
}  
}  
},  
"must": {  
"match": { "someKey": "someString" }  
}  
},  
"filtered": {  
...  
}  
},  
}

and ES responds as expected. OTOH, some developers (don't know why) guess  
json object is similar to Map (i.e. there isn't duplicating keys). I just  
want to be sure current (correct, to my mind) behavior is intentional and  
will not change.

Accompanying question: is there another (probably more preferred) way to  
AND queries?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Perry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/perry/32/2185_2.png) [@Perry](https://discuss.elastic.co/u/Perry)
#### Post date: [July 24, 2013, 1:22am UTC](https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907/2 "2013-07-24T01:22:18Z")

</div>

this should work too.

{  
"query": {  
"bool": {  
"must": [  
{  
"term": { "someFlag": true }  
},  
{  
"range" : {  
"someNumber" : {  
"from" : 50000,  
"to" : 2000000  
}  
}  
},  
{  
"match": { "someKey": "someString" }  
}]  
},  
"filtered": {  
...  
}  
},  
}

On Wed, Jul 24, 2013 at 12:44 AM, Andrew Gaydenko \<[andrew.gaydenko@gmail.com](mailto:andrew.gaydenko@gmail.com)

> wrote:

> [json.org](http://json.org) doesn't prevent from using the same name key in the same  
> sequence of (key, value) pairs. So I have tried (in sense) multiple musts
> 
> {  
> "query": {  
> "bool": {  
> "must": {  
> "term": { "someFlag": true }  
> },  
> "must": {  
> "range" : {  
> "someNumber" : {  
> "from" : 50000,  
> "to" : 2000000  
> }  
> }  
> },  
> "must": {  
> "match": { "someKey": "someString" }  
> }  
> },  
> "filtered": {  
> ...  
> }  
> },  
> }
> 
> and ES responds as expected. OTOH, some developers (don't know why) guess  
> json object is similar to Map (i.e. there isn't duplicating keys). I just  
> want to be sure current (correct, to my mind) behavior is intentional and  
> will not change.
> 
> Accompanying question: is there another (probably more preferred) way to  
> AND queries?
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Perry | 彭琪  
[http://pengqi.me](http://pengqi.me)

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Andrew\_Gaydenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_gaydenko/32/914_2.png) [@Andrew\_Gaydenko](https://discuss.elastic.co/u/Andrew_Gaydenko)
#### Post date: [July 24, 2013, 7:28am UTC](https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907/3 "2013-07-24T07:28:01Z")

</div>

On Wednesday, July 24, 2013 5:22:18 AM UTC+4, Qi Peng wrote:

> this should work too.

It is a bit shorter, thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:24am UTC](https://discuss.elastic.co/t/bool-query-multiple-musts-and-json-legality/12907/4 "2017-07-06T02:24:50Z")

</div>


