Elasticsearch – Advance Query [DSL Filter Context]

Filters don’t have relevance scores. And filters are cached, so queries that we have already run, elasticsearch is going to cached. The filter is faster than a query. A basic filter example.

Filter query with a must

.Filter query with must and must_not.

Two must query with filter. And here we will get a relevance score because the second must is not under the filter, it’s under the query. This is a very good example of a hybrid query. We use filter to get quickly get only those documents we care without the need of relevancy, then we get the relevance data using must outside the filter, and inside the query context.

Filter and Range query hybrid query.

This will use a multi_match if the “market” exists within the name or course_description field or both. If both fields it will have a higher relevance compared to a single field. But we can alter the relevance score that assigned to the document based on which field you consider more important, and that’s called field boosting.