@@ -29,26 +29,45 @@ parameter, such as the `query` parameter in the
2929[discrete]
3030[[filter-context]]
3131=== Filter context
32- In a filter context, a query clause answers the question ``__Does this
33- document match this query clause?__'' The answer is a simple Yes or No -- no
34- scores are calculated. Filter context is mostly used for filtering structured
35- data, e.g.
3632
37- * __Does this +timestamp+ fall into the range 2015 to 2016?__
38- * __Is the +status+ field set to ++"published"++__?
33+ A filter answers the binary question “Does this document match this query clause?”. The answer is simply "yes" or "no".
34+ Filtering has several benefits:
3935
40- Frequently used filters will be cached automatically by Elasticsearch, to
41- speed up performance.
36+ . *Simple binary logic*: In a filter context, a query clause determines document matches based on a yes/no criterion, without score calculation.
37+ . *Performance*: Because they don't compute relevance scores, filters execute faster than queries.
38+ . *Caching*: {es} automatically caches frequently used filters, speeding up subsequent search performance.
39+ . *Resource efficiency*: Filters consume less CPU resources compared to full-text queries.
40+ . *Query combination*: Filters can be combined with scored queries to refine result sets efficiently.
4241
43- Filter context is in effect whenever a query clause is passed to a `filter`
44- parameter, such as the `filter` or `must_not` parameters in the
45- <<query-dsl-bool-query,`bool`>> query, the `filter` parameter in the
46- <<query-dsl-constant-score-query,`constant_score`>> query, or the
47- <<search-aggregations-bucket-filter-aggregation,`filter`>> aggregation.
42+ Filters are particularly effective for querying structured data and implementing "must have" criteria in complex searches.
43+
44+ Structured data refers to information that is highly organized and formatted in a predefined manner. In the context of Elasticsearch, this typically includes:
45+
46+ * Numeric fields (integers, floating-point numbers)
47+ * Dates and timestamps
48+ * Boolean values
49+ * Keyword fields (exact match strings)
50+ * Geo-points and geo-shapes
51+
52+ Unlike full-text fields, structured data has a consistent, predictable format, making it ideal for precise filtering operations.
53+
54+ Common filter applications include:
55+
56+ * Date range checks: for example is the `timestamp` field between 2015 and 2016
57+ * Specific field value checks: for example is the `status` field equal to "published" or is the `author` field equal to "John Doe"
58+
59+ Filter context applies when a query clause is passed to a `filter` parameter, such as:
60+
61+ * `filter` or `must_not` parameters in <<query-dsl-bool-query,`bool`>> queries
62+ * `filter` parameter in <<query-dsl-constant-score-query,`constant_score`>> queries
63+ * <<search-aggregations-bucket-filter-aggregation,`filter`>> aggregations
64+
65+ Filters optimize query performance and efficiency, especially for structured data queries and when combined with full-text searches.
4866
4967[discrete]
5068[[query-filter-context-ex]]
5169=== Example of query and filter contexts
70+
5271Below is an example of query clauses being used in query and filter context
5372in the `search` API. This query will match documents where all of the following
5473conditions are met:
@@ -93,4 +112,4 @@ significand's precision will be converted to floats with loss of precision.
93112
94113TIP: Use query clauses in query context for conditions which should affect the
95114score of matching documents (i.e. how well does the document match), and use
96- all other query clauses in filter context.
115+ all other query clauses in filter context.
0 commit comments