|
1 | 1 | [[mapping-boost-field]]
|
2 | 2 | === `_boost`
|
3 | 3 |
|
| 4 | +deprecated[1.0.0.RC1,See <<function-score-instead-of-boost>>] |
| 5 | + |
4 | 6 | Boosting is the process of enhancing the relevancy of a document or
|
5 | 7 | field. Field level mapping allows to define explicit boost level on a
|
6 | 8 | specific field. The boost field mapping (applied on the
|
@@ -30,3 +32,41 @@ following JSON document will be indexed with a boost value of `2.2`:
|
30 | 32 | "message" : "This is a tweet!"
|
31 | 33 | }
|
32 | 34 | --------------------------------------------------
|
| 35 | + |
| 36 | +[[function-score-instead-of-boost]] |
| 37 | +==== Function score instead of boost |
| 38 | + |
| 39 | +Support for document boosting via the `_boost` field has been removed |
| 40 | +from Lucene and is deprecated in Elasticsearch as of v1.0.0.RC1. The |
| 41 | +implementation in Lucene resulted in unpredictable result when |
| 42 | +used with multiple fields or multi-value fields. |
| 43 | + |
| 44 | +Instead, the <<query-dsl-function-score-query>> can be used to achieve |
| 45 | +the desired functionality by boosting each document by the value in |
| 46 | +any field the document: |
| 47 | + |
| 48 | +[source,js] |
| 49 | +-------------------------------------------------- |
| 50 | +{ |
| 51 | + "query": { |
| 52 | + "function_score": { |
| 53 | + "query": { <1> |
| 54 | + "match": { |
| 55 | + "title": "your main query" |
| 56 | + } |
| 57 | + }, |
| 58 | + "functions": [{ |
| 59 | + "script_score": { <2> |
| 60 | + "script": "doc['my_boost_field'].value" |
| 61 | + } |
| 62 | + }], |
| 63 | + "score_mode": "multiply" |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +-------------------------------------------------- |
| 68 | +<1> The original query, now wrapped in a `function_score` query. |
| 69 | +<2> This script returns the value in `my_boost_field`, which is then |
| 70 | + multiplied by the query `_score` for each document. |
| 71 | + |
| 72 | + |
0 commit comments