| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 | [[query-dsl-filters]]== FiltersAs a general rule, filters should be used instead of queries:* for binary yes/no searches* for queries on exact values[float][[caching]]=== Filters and CachingFilters can be a great candidate for caching. Caching the result of afilter does not require a lot of memory, and will cause other queriesexecuting against the same filter (same parameters) to be blazinglyfast.Some filters already produce a result that is easily cacheable, and thedifference between caching and not caching them is the act of placingthe result in the cache or not. These filters, which include the<<query-dsl-term-filter,term>>,<<query-dsl-terms-filter,terms>>,<<query-dsl-prefix-filter,prefix>>, and<<query-dsl-range-filter,range>> filters, are bydefault cached and are recommended to use (compared to the equivalentquery version) when the same filter (same parameters) will be usedacross multiple different queries (for example, a range filter with agehigher than 10).Other filters, usually already working with the field data loaded intomemory, are not cached by default. Those filters are already very fast,and the process of caching them requires extra processing in order toallow the filter result to be used with different queries than the oneexecuted. These filters, including the geo,and <<query-dsl-script-filter,script>> filtersare not cached by default.The last type of filters are those working with other filters. The<<query-dsl-and-filter,and>>,<<query-dsl-not-filter,not>> and<<query-dsl-or-filter,or>> filters are notcached as they basically just manipulate the internal filters.All filters allow to set `_cache` element on them to explicitly controlcaching. They also allow to set `_cache_key` which will be used as thecaching key for that filter. This can be handy when using very largefilters (like a terms filter with many elements in it).include::filters/and-filter.asciidoc[]include::filters/bool-filter.asciidoc[]include::filters/exists-filter.asciidoc[]include::filters/geo-bounding-box-filter.asciidoc[]include::filters/geo-distance-filter.asciidoc[]include::filters/geo-distance-range-filter.asciidoc[]include::filters/geo-polygon-filter.asciidoc[]include::filters/geo-shape-filter.asciidoc[]include::filters/geohash-cell-filter.asciidoc[]include::filters/has-child-filter.asciidoc[]include::filters/has-parent-filter.asciidoc[]include::filters/ids-filter.asciidoc[]include::filters/indices-filter.asciidoc[]include::filters/limit-filter.asciidoc[]include::filters/match-all-filter.asciidoc[]include::filters/missing-filter.asciidoc[]include::filters/nested-filter.asciidoc[]include::filters/not-filter.asciidoc[]include::filters/or-filter.asciidoc[]include::filters/prefix-filter.asciidoc[]include::filters/query-filter.asciidoc[]include::filters/range-filter.asciidoc[]include::filters/regexp-filter.asciidoc[]include::filters/script-filter.asciidoc[]include::filters/term-filter.asciidoc[]include::filters/terms-filter.asciidoc[]include::filters/type-filter.asciidoc[]
 |