Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4438d2a
Add search and filtering tutorial, edit filtering page
leemthompo Oct 8, 2024
f32b83a
Fix example syntax
leemthompo Oct 9, 2024
59d98cc
Fix syntax
leemthompo Oct 9, 2024
acd0055
Merge branch 'main' into qs-full-text
elasticmachine Oct 9, 2024
549f110
Merge branch 'main' into qs-full-text
leemthompo Oct 11, 2024
7a0ead7
Typos
leemthompo Oct 11, 2024
3abc6c8
Apply Carlos' suggestions
leemthompo Oct 14, 2024
23f292a
Fix syntax
leemthompo Oct 14, 2024
92e47af
Sharpen tutorial focus, explain queries and responses, etc
leemthompo Oct 15, 2024
a3c6c87
Fix test?
leemthompo Oct 16, 2024
262a15b
docscheck CI whackamole
leemthompo Oct 16, 2024
75c52de
Add links to Query DSL, mapping types, and bool query; expanded multi…
leemthompo Oct 16, 2024
e00dbbd
Add link to search api
leemthompo Oct 16, 2024
7d92427
Will docscheck work now?
leemthompo Oct 16, 2024
4ca8132
Use substitutions in response test
leemthompo Oct 16, 2024
b677609
Comment out flakey test
leemthompo Oct 16, 2024
faa12a5
Add step numbers
leemthompo Oct 16, 2024
9970a34
Clarify filtering overview
leemthompo Oct 23, 2024
0de3031
Address Kathleen's feedback
leemthompo Oct 23, 2024
83b409a
fix yaml
shainaraskas Oct 24, 2024
dacbe7c
Fix docscheck?
leemthompo Oct 25, 2024
1295518
Is explicit analyzer here messing things up?
leemthompo Oct 25, 2024
b46725a
Fix wording
leemthompo Oct 25, 2024
0624b19
Merge branch 'main' into qs-full-text
elasticmachine Oct 25, 2024
ab1f11b
Desperado
leemthompo Oct 25, 2024
df4184a
Change query
leemthompo Oct 25, 2024
2488afd
Split index creation + mapping steps and add refresh param for better…
leemthompo Oct 25, 2024
9589b6a
Update result text
leemthompo Oct 25, 2024
9cce834
Fix took time
leemthompo Oct 25, 2024
3eafe1b
Fix test syntax, json spacing🤞
leemthompo Oct 28, 2024
a083d42
Fixes per Mike's final pass
leemthompo Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions docs/reference/query-dsl/query_filter_context.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,35 @@ parameter, such as the `query` parameter in the
[discrete]
[[filter-context]]
=== Filter context
In a filter context, a query clause answers the question ``__Does this
document match this query clause?__'' The answer is a simple Yes or No -- no
scores are calculated. Filter context is mostly used for filtering structured
data, e.g.

* __Does this +timestamp+ fall into the range 2015 to 2016?__
* __Is the +status+ field set to ++"published"++__?
A filter answers the binary question “Does this document match this query clause?”. The anwser is simply "yes" or "no".
Filtering has several benefits:

Frequently used filters will be cached automatically by Elasticsearch, to
speed up performance.
. *Simple binary logic*: In a filter context, a query clause determines document matches based on a yes/no criterion, without score calculation.
. *Performance*: Because they don't compute relevance scores, filters execute faster than queries.
. *Caching*: {es} automatically caches frequently used filters, speeding up subsequent search performance.
. *Resource efficiency*: Filters consume less CPU resources compared to full-text queries.
. *Query combination*: Filters can be combined with scored queries to refine result sets efficiently.

Filter context is in effect whenever a query clause is passed to a `filter`
parameter, such as the `filter` or `must_not` parameters in the
<<query-dsl-bool-query,`bool`>> query, the `filter` parameter in the
<<query-dsl-constant-score-query,`constant_score`>> query, or the
<<search-aggregations-bucket-filter-aggregation,`filter`>> aggregation.
Filters are particularly effective for querying structured data and implementing "must have" criteria in complex searches.

Common filter applications include:

* Date range checks: for example is the `timestamp` field between 2015 and 2016
* Status checks: for example is the `status` field equals "published"

Filter context applies when a query clause is passed to a `filter` parameter, such as:

* `filter` or `must_not` parameters in <<query-dsl-bool-query,`bool`>> queries
* `filter` parameter in <<query-dsl-constant-score-query,`constant_score`>> queries
* <<search-aggregations-bucket-filter-aggregation,`filter`>> aggregations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add knn here as an example as well?

Copy link
Contributor Author

@leemthompo leemthompo Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit too much in this 101 searching and filtering intro! This is the first tentative toe in the search paddling pool. 🦶

Currently I'm thinking the next basics "quickstart" could be asemantic_text quickstart (maybe ELSER + hybrid via rrf). That would be a toy example, API-only, with no reindexing or anything, just the happiest path — and then link to Search your data for the full-blown semantic search examples.

Copy link
Contributor Author

@leemthompo leemthompo Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a little too much in this first draft already, let's see how we feel once I've incorporated the first round of feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlosdelest sorry I forgot that I edited this page too, so I glanced over this comment as if it related to the tutorial!

Indeed we should add whatever else is missing from this query_filter_context.asciidoc page too 😄


Filters optimize query performance and efficiency, especially for structured data queries and when combined with full-text searches.

[discrete]
[[query-filter-context-ex]]
=== Example of query and filter contexts

Below is an example of query clauses being used in query and filter context
in the `search` API. This query will match documents where all of the following
conditions are met:
Expand Down
Loading