The behaviour of a query clause depends on whether it is used in query context or in filter context:
- Query context
A query clause used in query context answers the question “How well does this document match this query clause?” Besides deciding whether or not the document matches, the query clause also calculates a
_scorerepresenting how well the document matches, relative to other documents.
Query context is in effect whenever a query clause is passed to a
queryparameter, such as the
queryparameter in the
- Filter context
In filter context, a query clause answers the question “Does this document match this query clause?” The answer is a simple Yes or No — no scores are calculated. Filter context is mostly used for filtering structured data, e.g.
timestampfall into the range 2015 to 2016?
statusfield set to
Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.
Filter context is in effect whenever a query clause is passed to a
filterparameter, such as the
must_notparameters in the
filterparameter in the
constant_scorequery, or the
- Does this
Below is an example of query clauses being used in query and filter context
search API. This query will match documents where all of the following
conditions are met:
titlefield contains the word
contentfield contains the word
statusfield contains the exact word
publish_datefield contains a date from 1 Jan 2015 onwards.
Use query clauses in query context for conditions which should affect the score of matching documents (i.e. how well does the document match), and use all other query clauses in filter context.