# Filter cache implementation details

**URL:** <https://discuss.elastic.co/t/filter-cache-implementation-details/21035>\
**Category:** Elasticsearch\
**Created:** [December 2, 2014, 3:56pm UTC](https://discuss.elastic.co/t/filter-cache-implementation-details/21035 "2014-12-02T15:56:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Koval](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_koval/32/1079_2.png) [@Alexander\_Koval](https://discuss.elastic.co/u/Alexander_Koval)\
**Post date:** [December 2, 2014, 3:56pm UTC](https://discuss.elastic.co/t/filter-cache-implementation-details/21035/1 "2014-12-02T15:56:59Z")

</div>

As specified in documentation node-filter-cache  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-cache.html#node-filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-cache.html#node-filter)  
:

The cache implements an LRU eviction policy: when a cache becomes full, the

> least recently used data is evicted to make way for new data.

But in source code I found filter cache implementation:

- IndicesFilterCache  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java#L132](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java#L132)
- FilterCacheValueWeigher  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java#L220](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java#L220)

So the cache will evict entries that consumes more memory. I think this  
policy is not the best choice cause fat entries can be used quite  
frequently. May be there should be several implementation of filter cache  
as Solr does.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 3, 2014, 1:34pm UTC](https://discuss.elastic.co/t/filter-cache-implementation-details/21035/2 "2014-12-03T13:34:36Z")

</div>

I don't think the current filter cache evicts entries that consume more  
memory first. The weight part is only used to evict when the filter cache  
size (in terms of bytes, not entries) grows beyond a configured limit.

I agree this behaviour is quite simplistic and there are two interesting  
things that can be improved:

- the decision about which entries to evict first
- the decision about which entries to cache at all

If you are interested, there are improvements currently being worked on for  
the later issue: [Filter cache: add a `_cache: auto` option and make it the default. by jpountz · Pull Request #8573 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/pull/8573)

On Tue, Dec 2, 2014 at 4:56 PM, Alexander Koval [kovalidis@gmail.com](mailto:kovalidis@gmail.com) wrote:

> As specified in documentation node-filter-cache  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-cache.html#node-filter](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-cache.html#node-filter)  
> :
> 
> The cache implements an LRU eviction policy: when a cache becomes full,
> 
> > the least recently used data is evicted to make way for new data.
> 
> But in source code I found filter cache implementation:
> 
> - IndicesFilterCache  
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java#L132](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java#L132)
> - FilterCacheValueWeigher  
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java#L220](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/cache/filter/weighted/WeightedFilterCache.java#L220)
> 
> So the cache will evict entries that consumes more memory. I think this  
> policy is not the best choice cause fat entries can be used quite  
> frequently. May be there should be several implementation of filter cache  
> as Solr does.
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/aea81973-2aa1-4f14-9832-6a1ffef3cd30%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6pyv4G%2BbSSczxg3k6KtA17f1iMMU%3DX%3DwX4o-xe3jdvQA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6pyv4G%2BbSSczxg3k6KtA17f1iMMU%3DX%3DwX4o-xe3jdvQA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:46am UTC](https://discuss.elastic.co/t/filter-cache-implementation-details/21035/3 "2017-07-06T00:46:15Z")

</div>


