Elasticsearch Query DSL - Query Context vs Filter Context

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.

Learn Serverless from Serverless Programming Cookbook

Contact

Please first use the contact form or facebook page messaging to connect.

Offline Contact
We currently connect locally for discussions and sessions at Bangalore, India. Please follow us on our facebook page for details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.

About

CloudMaterials is my blog to share notes and learning materials on Cloud and Data Analytics. My current focus is on Microsoft Azure and Amazon Web Services (AWS).

I like to write and I try to document what I learn to share with others. I believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream