A query context evaluates whether documents match and how well they match. Elasticsearch selects the context from the query: full-text match queries run in query context and produce relevance scores. section 8.4.2
Finding Godfather movies
GET movies/_search { "query": { "match": { "title": "Godfather" } } } Both matching movies receive an _score. “The Godfather” scores higher than “The Godfather: Part II” because the matching term appears in the shorter title. section 8.4.2
Use query context when relevance affects the result order:
- A match query searches analyzed field values and scores documents according to how well they match. section 8.4.2
- In a bool query, must and should clauses run in query context; should clauses can increase a matching document’s score. section 11.3.6
- A filter clause answers only whether documents match, returning a score of 0.0 instead of calculating relevance. section 8.4.2
Listing 8.3 Match query executed in a query context
GET movies/_search
{
"query": {
"match": {
"title": "Godfather"
}
}
}
Open the complete REST request for the Godfather match query and its query-context execution. section 8.4.2
