WARNING: Version 1.4 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
_boost
edit_boost
editDeprecated in 1.0.0.RC1.
Boosting is the process of enhancing the relevancy of a document or field. Field level mapping allows to define an explicit boost level on a specific field. The boost field mapping (applied on the root object) allows to define a boost field mapping where its content will control the boost level of the document. For example, consider the following mapping:
{ "tweet" : { "_boost" : {"name" : "my_boost", "null_value" : 1.0} } }
The above mapping defines a mapping for a field named my_boost
. If the
my_boost
field exists within the JSON document indexed, its value will
control the boost level of the document indexed. For example, the
following JSON document will be indexed with a boost value of 2.2
:
{ "my_boost" : 2.2, "message" : "This is a tweet!" }
Function score instead of boost
editSupport for document boosting via the _boost
field has been removed
from Lucene and is deprecated in Elasticsearch as of v1.0.0.RC1. The
implementation in Lucene resulted in unpredictable result when
used with multiple fields or multi-value fields.
Instead, the Function Score Query can be used to achieve the desired functionality by boosting each document by the value in any field of the document:
{ "query": { "function_score": { "query": { "match": { "title": "your main query" } }, "functions": [{ "field_value_factor": { "field": "my_boost_field" } }], "score_mode": "multiply" } } }
The original query, now wrapped in a |
|
This function returns the value in |
Note, that field_value_factor
is a 1.2.x feature.