Slow execution of nested boolean filter

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:

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/30643d57-4ad3-4101-b0c8-d6a788f7cd6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.