elasticsearch/elasticsearch — Issue #1568: Query DSL: Add different execution models for terms filter
Author: kimchy
Created: 2011-12-23 22:29:38+00:00
State: open
Labels: enhancement, v0.19.0

The way `terms` filter currently executes is by iterating over the terms provided and finding matches docs (loading into a bitset) and caching it. Sometimes, we want a different execution model that can still be achieved by building more complex queries in the DSL, but would be nice to support them in the more compact model that `terms` filter provides.

The `execution` option now has the following options :

* `plain`: The default. Works as today. Iterates over all the terms, building a bit set matching it, and filtering. The total filter is cached (keyed by the terms).
* `bool`: Builds a `bool` filter wrapping each term in a `term` filter that is cached. The bool filter is optimized in this case since it bitwise or's the different term filter bitsets. The total filter is not cached by default in this case.
* `and`: Builds an `and` filter wrapping each term in `term` filter that is cached. The total filter is not cached by default in this case. Most times, `bool` should be used as its faster thanks to its bitwise execution.

The "total" terms filter caching can still be explicitly controlled using the `_cache` option. Note the default value for it depends on the `execution` value.