# Best caching strategy: filter only vs filtered query with \_cache:true

**URL:** <https://discuss.elastic.co/t/best-caching-strategy-filter-only-vs-filtered-query-with--cache-true/46531>\
**Category:** Elasticsearch\
**Created:** [April 6, 2016, 1:09pm UTC](https://discuss.elastic.co/t/best-caching-strategy-filter-only-vs-filtered-query-with--cache-true/46531 "2016-04-06T13:09:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zsolt](https://avatars.discourse-cdn.com/v4/letter/z/58956e/32.png) [@Zsolt](https://discuss.elastic.co/u/Zsolt)\
**Post date:** [April 6, 2016, 1:09pm UTC](https://discuss.elastic.co/t/best-caching-strategy-filter-only-vs-filtered-query-with--cache-true/46531/1 "2016-04-06T13:09:41Z")

</div>

I wonder what is the best solution for an autocomplete/lookup type of solution when we don't care for score.

We have an index with accounts per customers where the account number is analyzed by edgeNGram and the account name by nGram.

As I can see, I have the following options:

- Filtered query with \_cache: true and constant\_score query:

`"query" : { "filtered" : { "filter" : { "bool" : { "_cache" : true, "must" : [{ "term" : { "customer" : "xyz" } }], "must_not" : [{ "term" : { "inactive" : true } }] } }, "query" : { "constant_score" : { "query" : { "bool" : { "should" : [{ "term" : { "acc_no" : "123" } }, { "term" : { "acc_name" : "123" } }] } } } } } }`

- Filter only and let elastic handle the caching

`"filter": { "bool": { "must": [{ "term": { "customer": "xyz" } }], "must_not": [{ "term": { "inactive": true } }], "should": [{ "term": { "acc_no": "123" } }, { "term": { "acc_name": "123" } }] } }`

My problem with using the \_cache: true is that I think that the customer filter will not be reused for other type of searches (projects etc) while the filter only will cache too much (?). Any inputs?

We are on 1.7.5 for now.

Thanks

---

<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:01pm UTC](https://discuss.elastic.co/t/best-caching-strategy-filter-only-vs-filtered-query-with--cache-true/46531/2 "2017-07-05T23:01:53Z")

</div>

Closed on July 5, 2017, 11:01pm UTC


