# Bool must behaviour

**URL:** <https://discuss.elastic.co/t/bool-must-behaviour/7575>\
**Category:** Elasticsearch\
**Created:** [May 6, 2012, 3:41pm UTC](https://discuss.elastic.co/t/bool-must-behaviour/7575 "2012-05-06T15:41:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [May 6, 2012, 3:41pm UTC](https://discuss.elastic.co/t/bool-must-behaviour/7575/1 "2012-05-06T15:41:51Z")

</div>

Hi all when running the query containing:

```
            "bool": {
                "must":
                    {
                        "term": {
                            "operators": [
                                "35",
                                "12",
                                "51",
                                "55",
                                "14",
                                "29"
                            ]
                        }
                    }

```

sometimes the result is empty and sometimes it has values and I cant  
make out why, full example at

> <https://gist.github.com/anonymous/e0512a077960469fca54>

The actual data has many "operators" this is just a simplified version  
I cant figure why

"operators": ["35", "12", "51", "55", "14", "19"] fails  
"operators": ["35", "12", "51", "55", "14", "29"] works

once a match is found does every following value have to be a match?  
I am truing to replicate an SQL condition "where operators in ('35',  
'12', "51', '55', '14', '29')"

Running elasticsearch 0.18.7 java version 7

---

<div class="post-metadata">

**Author:** ![medcl\_net](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@medcl\_net](https://discuss.elastic.co/u/medcl_net)\
**Post date:** [May 7, 2012, 2:29am UTC](https://discuss.elastic.co/t/bool-must-behaviour/7575/2 "2012-05-07T02:29:53Z")

</div>

you should use terms-query or terms-filter instead of term query,  
[http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter.html](http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter.html)

"bool": {  
"must":  
{  
"terms": {  
"operators": [  
"35",  
"12",  
"51",  
"55",  
"14",  
"29"  
]  
}  
}

-----Original Message-----  
From: GX  
Sent: Sunday, May 06, 2012 11:41 PM  
To: elasticsearch  
Subject: bool must behaviour

Hi all when running the query containing:

```
            "bool": {
                "must":
                    {
                        "term": {
                            "operators": [
                                "35",
                                "12",
                                "51",
                                "55",
                                "14",
                                "29"
                            ]
                        }
                    }

```

sometimes the result is empty and sometimes it has values and I cant  
make out why, full example at

> <https://gist.github.com/anonymous/e0512a077960469fca54>

The actual data has many "operators" this is just a simplified version  
I cant figure why

"operators": ["35", "12", "51", "55", "14", "19"] fails  
"operators": ["35", "12", "51", "55", "14", "29"] works

once a match is found does every following value have to be a match?  
I am truing to replicate an SQL condition "where operators in ('35',  
'12', "51', '55', '14', '29')"

Running elasticsearch 0.18.7 java version 7

---

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [May 7, 2012, 2:55am UTC](https://discuss.elastic.co/t/bool-must-behaviour/7575/3 "2012-05-07T02:55:09Z")

</div>

Thanks for the reply.

A stupid oversight in my part, it works now.

GX

On May 7, 5:29 am, [medcl2...@gmail.com](mailto:medcl2...@gmail.com) wrote:

> you should use terms-query or terms-filter instead of term query,[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter.html)
> 
> "bool": {  
> "must":  
> {  
> "terms": {  
> "operators": [  
> "35",  
> "12",  
> "51",  
> "55",  
> "14",  
> "29"  
> ]  
> }  
> }
> 
> -----Original Message-----  
> From: GX  
> Sent: Sunday, May 06, 2012 11:41 PM  
> To: elasticsearch  
> Subject: bool must behaviour
> 
> Hi all when running the query containing:
> 
> ```
> "bool": {
> "must":
> {
> "term": {
> "operators": [
> "35",
> "12",
> "51",
> "55",
> "14",
> "29"
> ]
> }
> }
> 
> ```
> 
> sometimes the result is empty and sometimes it has values and I cant  
> make out why, full example athttps://gist.github.com/e0512a077960469fca54
> 
> The actual data has many "operators" this is just a simplified version  
> I cant figure why
> 
> "operators": ["35", "12", "51", "55", "14", "19"] fails  
> "operators": ["35", "12", "51", "55", "14", "29"] works
> 
> once a match is found does every following value have to be a match?  
> I am truing to replicate an SQL condition "where operators in ('35',  
> '12', "51', '55', '14', '29')"
> 
> Running elasticsearch 0.18.7 java version 7

---

<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, 3:29am UTC](https://discuss.elastic.co/t/bool-must-behaviour/7575/4 "2017-07-06T03:29:57Z")

</div>


