# Please help me understand the Bool filter

**URL:** <https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333>\
**Category:** Elasticsearch\
**Created:** [June 8, 2013, 11:11pm UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333 "2013-06-08T23:11:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwisarts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwisarts/32/2004_2.png) [@kwisarts](https://discuss.elastic.co/u/kwisarts)\
**Post date:** [June 8, 2013, 11:11pm UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333/1 "2013-06-08T23:11:30Z")

</div>

These are essentially two questions:

1. How does the should part of a Bool filter influence the results  
returned?  
Could one say that where must creates an _AND_ combination of filters,  
should creates an _OR_?

2. I have used the Bool filter in something that I now realize, makes  
little sense. However, also don't understand its behavior:  
Given I have documents in my index which can have either value of _en_, _de_or  
_fr_ for the field _locale_, the following filter returns results with the  
locale being either _en_ or _fr_:

{  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"tags.komma": "common",  
"\_cache": false  
}  
}  
],  
"must\_not": [],  
"should": [  
{  
"term": {  
"locale": "en",  
"\_cache": false  
}  
}  
],  
"\_cache": false  
}  
}  
}

Here's the result (silly, but functional example data):

{  
took: 1  
timed\_out: false  
\_shards: {  
total: 5  
successful: 5  
failed: 0  
}  
hits: {  
total: 4  
max\_score: 1  
hits: [  
{  
\_index: fde  
\_type: booth  
\_id: NbmePfyGQsKVR5F1gJ1phg  
\_score: 1  
\_source: {  
idbooth: 40  
idorganisation: 3  
location: 3C13  
name: English booth name  
description: English booth desc  
locale: en  
tags: common  
}  
}  
{  
\_index: fde  
\_type: booth  
\_id: HRBspOmTQ3C1y0jKRfw2FQ  
\_score: 1  
\_source: {  
idbooth: 40  
idorganisation: 3  
location: 3C13  
name: Nom français  
description: Descriptions française  
locale: fr  
tags: common  
}  
}  
{  
\_index: fde  
\_type: booth  
\_id: Qe6MkFdtQx-7h3YNCBZNDQ  
\_score: 1  
\_source: {  
idbooth: 38  
idorganisation: 3  
location: 3C11  
tags: booth-tag1, booth-tag-2, common  
name: Booth name  
description: Booth description  
locale: en  
}  
}  
{  
\_index: fde  
\_type: booth  
\_id: ULOdnX6hTxikQe7kHEpFiA  
\_score: 1  
\_source: {  
idbooth: 41  
idorganisation: 3  
location: 3C45  
tags: sdf, sdfg, common  
name: Second  
description: I was indexed, but not saved?  
locale: en  
}  
}  
]  
}

}

The same result is being returned if I set _locale_ to be _fr_.

If I use _de_ for the _locale_ field in should, I get

{

```
took: 1
timed_out: false
_shards: {
    total: 5
    successful: 5
    failed: 0
}
hits: {
    total: 2
    max_score: 1
    hits: [
        {
            _index: fde
            _type: booth
            _id: JMHUR79zT0SdoCir04EOrg
            _score: 1
            _source: {
                idbooth: 43
                idorganisation: 3
                location: 3C87
                tags: sdf, common
                name: Des isch a Tyroler Universität
                description: Isch des
                locale: de
            }
        }
        {
            _index: fde
            _type: booth
            _id: pcgnocJeRJSIPGpt0W206A
            _score: 1
            _source: {
                idbooth: 42
                idorganisation: 3
                location: 3C99
                tags: sdf, sdfg, common
                name: Neu, nur Deutsch
                description: Lei a deitsche Beschreibung is des
                locale: de
            }
        }
    ]
}

```

}

Question is: Why does the filter with should -\> locale -\> en/fr even show  
results where the should condition isn't met?

Best regards,  
David

--  
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:** ![kwisarts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwisarts/32/2004_2.png) [@kwisarts](https://discuss.elastic.co/u/kwisarts)\
**Post date:** [June 8, 2013, 11:22pm UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333/2 "2013-06-08T23:22:28Z")

</div>

On 09/06/13 01:11, David Raison wrote:

> 1. I have used the Bool filter in something that I now realize, makes  
> little sense. However, also don't understand its behavior:  
> Given I have documents in my index which can have either value of  
> /en/, /de/ or /fr/ for the field _locale_, the following filter  
> returns results with the locale being either /en/ or /fr/:

Well I have now indexed another set of data and now having should {  
locale: en } no longer returns "fr" results (nor "de").  
Maybe this was simply a hiccup.

Regards,  
David

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 9, 2013, 1:24am UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333/3 "2013-06-09T01:24:47Z")

</div>

Did you change refresh settings?  
Sounds like a refresh issue...

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 9 juin 2013 à 01:22, David Raison [draison@gmail.com](mailto:draison@gmail.com) a écrit :

> On 09/06/13 01:11, David Raison wrote:
> 
> > 1. I have used the Bool filter in something that I now realize, makes little sense. However, also don't understand its behavior:  
> > Given I have documents in my index which can have either value of en, de or fr for the field locale, the following filter returns results with the locale being either en or fr:
> 
> Well I have now indexed another set of data and now having should { locale: en } no longer returns "fr" results (nor "de").  
> Maybe this was simply a hiccup.
> 
> ## Regards, David
> 
> 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).

--  
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:** ![kwisarts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kwisarts/32/2004_2.png) [@kwisarts](https://discuss.elastic.co/u/kwisarts)\
**Post date:** [June 13, 2013, 6:30pm UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333/4 "2013-06-13T18:30:15Z")

</div>

Hi and sorry for the late reply.

Ah, no, I did not change any refresh settings.  
Where and when would one usually do something like that?

I assumed that dropping an entire index and recreating it, including the  
setup of analyzers and mapping would sort of reset everything.

Regards,  
David

On Sun, Jun 9, 2013 at 3:24 AM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Did you change refresh settings?  
> Sounds like a refresh issue...
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 9 juin 2013 à 01:22, David Raison [draison@gmail.com](mailto:draison@gmail.com) a écrit :
> 
> On 09/06/13 01:11, David Raison wrote:
> 
> 1. I have used the Bool filter in something that I now realize, makes  
> little sense. However, also don't understand its behavior:  
> Given I have documents in my index which can have either value of _en_, \*  
> de\* or _fr_ for the field _locale_, the following filter returns results  
> with the locale being either _en_ or _fr_:
> 
> Well I have now indexed another set of data and now having should {  
> locale: en } no longer returns "fr" results (nor "de").  
> Maybe this was simply a hiccup.
> 
> Regards,  
> David
> 
> --  
> 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).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/-GeCVCtE05E/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/-GeCVCtE05E/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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).

--  
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:31am UTC](https://discuss.elastic.co/t/please-help-me-understand-the-bool-filter/12333/5 "2017-07-06T02:31:22Z")

</div>


