# Bool filter cache

**URL:** <https://discuss.elastic.co/t/bool-filter-cache/38009>\
**Category:** Elasticsearch\
**Created:** [December 27, 2015, 5:40pm UTC](https://discuss.elastic.co/t/bool-filter-cache/38009 "2015-12-27T17:40:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [December 27, 2015, 5:40pm UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/1 "2015-12-27T17:40:20Z")

</div>

Hi,

If i have to use mutliple filters inside a BOOL filter, which one should i use:

```auto
{
    "filtered": {
        "filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "_cache": true,
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "_cache": true,
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

```

OR

```auto
{
    "filtered": {
        "filter": {
            "bool": {
                "_cache": true,
                "must": [
                    {
                        "term": {
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

```

And what are the differences?

---

<div class="post-metadata">

**Author:** ![voipoclay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voipoclay/32/4372_2.png) [@voipoclay](https://discuss.elastic.co/u/voipoclay)\
**Post date:** [December 27, 2015, 6:27pm UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/2 "2015-12-27T18:27:21Z")

</div>

What ES version are you using?

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [December 28, 2015, 7:43am UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/3 "2015-12-28T07:43:13Z")

</div>

Elasticsearch version is 1.5.2

---

<div class="post-metadata">

**Author:** ![voipoclay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/voipoclay/32/4372_2.png) [@voipoclay](https://discuss.elastic.co/u/voipoclay)\
**Post date:** [December 28, 2015, 8:14am UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/4 "2015-12-28T08:14:38Z")

</div>

```
{
    "filtered": {
        "filter": {
            "bool": {
                "_cache": true,
                "must": [
                    {
                        "term": {
                            "tag": "first"
                        }
                    },
                    {
                        "term": {
                            "tag": "second"
                        }
                    }
                ]
            }
        }
    }
}

```

I believe that is the only valid option of the two you provided.

I recommend the [sense plugin](https://chrome.google.com/webstore/detail/sense-beta/lhjgkmllcaadmopgmanpapmpjgmfcfig?hl=en)

---

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [December 28, 2015, 9:24am UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/5 "2015-12-28T09:24:33Z")

</div>

Why do you believe that? I think the other one is valid as well.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 28, 2015, 10:12am UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/6 "2015-12-28T10:12:50Z")

</div>

Right both options work. The difference is that the first approach will cache both clauses individually and recompute the intersection every time while the second one will cache the result of the bool query directly.

Note that the \_cache option does not exist anymore in elasticsearch 2.0: elasticsearch makes its own decisions regarding what to cache based on what filters are reused.

---

<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 5, 2017, 11:28pm UTC](https://discuss.elastic.co/t/bool-filter-cache/38009/7 "2017-07-05T23:28:18Z")

</div>


