Query context
Answers “how well does this document match?” Elasticsearch computes a relevance
_score for each document. Use for full-text search and ranking.Filter context
Answers “does this document match?” No score is computed. Results are cached automatically. Use for exact matches on dates, statuses, and keywords.
Prefer filter context for exact-match conditions. Filters are cached at the segment level and do not incur scoring overhead, which makes them significantly faster.
Sending queries
Queries are sent in the request body ofGET or POST requests to the /_search endpoint:
Leaf queries
Leaf queries look for a particular value in a particular field. They can be used on their own or combined inside compound queries.match
match
The standard query for full-text search. Analyzes the query string before matching.
term
term
Finds documents that contain an exact, unanalyzed value. Best for
keyword, numeric, and date fields.terms
terms
Like
term, but matches any value from a provided list.range
range
Matches documents with field values within a given range. Supports
gt, gte, lt, lte.exists
exists
Returns documents that have at least one non-null value for the specified field.
prefix
prefix
Matches documents where the field value starts with the given prefix. Runs on unanalyzed terms.
wildcard
wildcard
Matches documents using
* (any number of characters) and ? (single character) patterns.fuzzy
fuzzy
Matches terms that are similar to the query value, based on edit distance (Levenshtein distance). Useful for handling typos.
Full-text queries
Full-text queries analyze the query string using the same analyzer applied to the field at index time, then search for the analyzed tokens.match_phrase
match_phrase
Matches documents where the field contains the exact phrase, with tokens in the same order and position.
multi_match
multi_match
Runs a The
match query across multiple fields. Useful when you don’t know which field contains the value.^3 notation boosts the title field’s score by a factor of three.query_string
query_string
Parses a query using the Lucene query syntax. Supports field names, wildcards, boolean operators, and ranges inline in the query string.
Compound queries
Compound queries wrap leaf or other compound queries to combine or modify their behavior.bool query
Thebool query is the most commonly used compound query. It combines multiple clauses using four typed occurrences:
| Clause | Behavior |
|---|---|
must | Clause must match. Contributes to the score. |
should | Clause should match. Contributes to the score. |
must_not | Clause must not match. No score contribution. Runs in filter context. |
filter | Clause must match. No score contribution. Runs in filter context (cached). |
dis_max query
Returns documents matching any of the wrapped queries. The document score is the maximum score from any single matching clause, rather than the sum.function_score query
Modifies the scores of documents returned by a query using custom scoring functions such asweight, field_value_factor, gauss, or script_score.
Pagination
- from / size
- search_after
- scroll (deprecated)
The simplest approach. Works well for shallow pagination (up to ~10,000 results by default).
from is zero-indexed. The example above returns results 21–30.Sorting
By default, results are sorted by_score descending. You can override this with any field value.
