# Slow execution of nested boolean filter

**URL:** <https://discuss.elastic.co/t/slow-execution-of-nested-boolean-filter/19826>\
**Category:** Elasticsearch\
**Created:** [September 16, 2014, 9:21pm UTC](https://discuss.elastic.co/t/slow-execution-of-nested-boolean-filter/19826 "2014-09-16T21:21:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kireet\_Reddy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kireet_reddy/32/1071_2.png) [@Kireet\_Reddy](https://discuss.elastic.co/u/Kireet_Reddy)\
**Post date:** [September 16, 2014, 9:21pm UTC](https://discuss.elastic.co/t/slow-execution-of-nested-boolean-filter/19826/1 "2014-09-16T21:21:58Z")

</div>

I have a query with a nested boolean (boolean within a boolean) filter with  
a should clause that performs really terribly. But if I move the nested  
query up to top level, it performs as much as 50x faster. I am struggling  
to understand why this is the case. Here are the 2 forms:

> <https://gist.github.com/anonymous/cdbfbb940fa8da81019f>

You can see the "flattened" version simply repeats the query filter for  
each of the nested should clauses in the "nested" version. The initial  
"groups" terms filter is very selective. So I am thinking that the nested  
boolean filter query must somehow work on all documents rather than the  
ones filtered from that initial clause? Why would that be the case?

--  
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/30643d57-4ad3-4101-b0c8-d6a788f7cd6a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/30643d57-4ad3-4101-b0c8-d6a788f7cd6a%40googlegroups.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, 1:01am UTC](https://discuss.elastic.co/t/slow-execution-of-nested-boolean-filter/19826/2 "2017-07-06T01:01:51Z")

</div>


