Boost queries
Purpose
Boost queries can be combined with the main query. The main query yields documents based on search criteria. The boost query yields documents that for example match a category. Document scores of the main query and document scores of the boost queries are combined. Found documents are usually ordered on descending score. A boost query increases the score of documents matching the boost criteria, causing these documents to appear higher in the list of found documents compared to documents not matching the boost criteria.
Boost queries
- A term query can be used as boost query. A term query specifies one term value, for example category News. A term query further specifies a field, for example extra_category. A document matches the query if field extra_category contains the value News.
- A terms query can be used as boost query. A terms query specifies one or more term values. A terms query further specifies a field, for example extra_categories, containing multiple categories. A document matches the query if field extra_categories contains one or more of the specified term values.
- Multiple boost queries can be added to the main query. Each boost query contributes to the score of matching documents. A boost query includes a boost factor. This is the factor of the boost query relative to the main query and relative to other boost queries. The default value is 1.0. The main query has this default 1.0. The impact of a boost query can be increased by using a value greater than 1.0, and the impact can be reduced by using a factor between 0.0 and 1.0.
- Boost queries can be applied to fields containing one or multiple discrete values, such as categories. The field is of type keyword in this case. The field can also be of type boolean, number or date, to be matched by exact value. The field should not be of type text, such as field doc_title, because the field content is modified due to full text analysis. Note that a field like doc_title has a subfield doc_title.words that contains the original words of the title, not analyzed. This field can be used, using a terms query as boost query.
- Boost queries are combined with the main query by means of a boolean should query. The boost query contributes to the score of a document if the document matches, and does not contribute if the document does not match. It does not filter the document, as the boolean must query would do. Moreover the boost query may cause finding a document, also if the document does not match the criteria of the main query.