# Caching of filters (from child filters) then reusing later

**URL:** <https://discuss.elastic.co/t/caching-of-filters-from-child-filters-then-reusing-later/8940>\
**Category:** Elasticsearch\
**Created:** [September 6, 2012, 12:38am UTC](https://discuss.elastic.co/t/caching-of-filters-from-child-filters-then-reusing-later/8940 "2012-09-06T00:38:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 6, 2012, 12:38am UTC](https://discuss.elastic.co/t/caching-of-filters-from-child-filters-then-reusing-later/8940/1 "2012-09-06T00:38:29Z")

</div>

Am I correct that any filter can be set to "cache" : "true"?

How does ES realize that the filter is the same?  
By the cache\_key sure, but if I don't set it what is based on?  
What does the page  
[http://www.elasticsearch.org/guide/reference/query-dsl/](http://www.elasticsearch.org/guide/reference/query-dsl/)  
mean by same "parameters"? Does that include filter types sub filters,  
queries etc. and all the settings?

What happens if I use a \_cache\_key that is not unique?  
i.e. What would happen, if I reuse "\_cache\_key" : "allTheRightDocs"  
instead of considering that all unique values for this filter is  
different per user etc.?

Can I re-use a cached filter (assuming I get all the above correct) that  
I invoked in the filter of a filtered query?  
How about if I put a filtered query inside of a has\_child filter? After  
all it is a filter which returns children.  
In this last case, I think I want to make the round trip to back to my  
client and then ask for (some of) the children and various fields from  
them based on the set of children already identified.  
I don't have to use "scope" to do this do I? I'm thinking not, because  
the cached filter is a set of children IDs, just what I want the next  
time around and I'm not using them in a facet.

"query" : {  
"filtered": {  
.... filter parents  
"filter": {  
"has\_child" : {  
type: "myChildren"  
"filtered" : {  
"match\_all" : { },  
"filter" : { \<-- we want to save everything in  
this filter for the next search request  
"and" : {  
... all about the children fields and  
nothing else  
"cache" : "true"  
}  
}  
}  
}  
}  
}  
}

-Paul

--

---

<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:13am UTC](https://discuss.elastic.co/t/caching-of-filters-from-child-filters-then-reusing-later/8940/2 "2017-07-06T03:13:59Z")

</div>

Closed on July 6, 2017, 3:13am UTC


