Elasticsearch provides a full Query DSL based on JSON to define queries. The behaviour of a query clause depends on whether it is used in query context or in filter context.
In Query context, besides deciding whether or not the document matches, the query clause also calculates a _score representing how well the document matches, relative to other documents. Here, a query clause is passed to a query parameter, such as the query parameter in the search API.
In Filter context, no scores are calculated. Filter context is mostly used for filtering structured data. Frequently used filters will be cached automatically by Elasticsearch, to speed up performance. Here, the query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.
Relevance Scoring Algorithm
Until recently Elasticsearch was using Term Frequency (TF) / Inverse Document Frequency (IDC) for relevance scoring. Currently Elasticsearch uses an algorithm called Okapi BM25, which has better stop word handling.
- heartin's blog
- Log in or register to post comments
Recent comments