What is the difference between query context and filter context in Elasticsearch?
Answer
In Elasticsearch, query context asks "how well does this document match?" — it calculates a relevance score for each matching document. Use query context for full-text search where ranking by relevance matters (e.g., match query). Filter context asks "does this document match?" — it is a yes/no decision with no scoring, and results are automatically cached. Use filter context for structured data like status, date ranges, and boolean flags. In a bool query, clauses inside must and should contribute to the score (query context), while clauses inside filter and must_not do not (filter context). Always put non-scoring criteria in the filter clause for better performance.
Previous
What are the _id and _source fields in Elasticsearch?
Next
What is a bool query in Elasticsearch?
More Elasticsearch Questions
View all →- Intermediate What is a bool query in Elasticsearch?
- Intermediate What are aggregations in Elasticsearch?
- Intermediate What is the difference between text and keyword field types?
- Intermediate What are index templates and component templates in Elasticsearch?
- Intermediate What is the Reindex API and when would you use it?