A filtered query is faster than a top-level filter. Filtered queries first
apply the filter, then perform query phase on remaining documents.
Top-level filter first executes the query (e.g. on all documents), then
applies the top-level filter to docs that matched the query.
The only time to use a top-level filter is when you need to filter search
results but not facet results. Since top-level filters are applied after
queries, and facets get their data from the query results, top-level
filters don't affect the facet results at all. This can be useful in
certain situations, usually when you need the facet results in the UI to
not change.
So yeah, tl;dr: use filtered_query unless you are doing facets and need
specific behavior =)
-Zach
On Friday, August 30, 2013 5:22:34 PM UTC-4, asanderson wrote:
Is there any difference in performance (or otherwise) between using a
filtered query vs. a query with a filter at the same level?
A filtered query is faster than a top-level filter. Filtered queries
first apply the filter, then perform query phase on remaining documents.
Top-level filter first executes the query (e.g. on all documents), then
applies the top-level filter to docs that matched the query.
The only time to use a top-level filter is when you need to filter search
results but not facet results. Since top-level filters are applied after
queries, and facets get their data from the query results, top-level
filters don't affect the facet results at all. This can be useful in
certain situations, usually when you need the facet results in the UI to
not change.
So yeah, tl;dr: use filtered_query unless you are doing facets and need
specific behavior =)
Zach,
Thanks for the explanation. It would be great if the ES guide had this
explanation. Also, it would be great if top level filters had some
parameter that allowed one to specify before or after query phase.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.