1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
[[mapping-boost-field]]
=== `_boost`
deprecated[1.0.0.RC1,See <<function-score-instead-of-boost>>]
Boosting is the process of enhancing the relevancy of a document or
field. Field level mapping allows to define explicit boost level on a
specific field. The boost field mapping (applied on the
<<mapping-root-object-type,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:
[source,js]
--------------------------------------------------
{
"tweet" : {
"_boost" : {"name" : "my_boost", "null_value" : 1.0}
}
}
--------------------------------------------------
The above mapping defines 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`:
[source,js]
--------------------------------------------------
{
"my_boost" : 2.2,
"message" : "This is a tweet!"
}
--------------------------------------------------
[[function-score-instead-of-boost]]
==== Function score instead of boost
Support 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 <<query-dsl-function-score-query>> can be used to achieve
the desired functionality by boosting each document by the value in
any field the document:
[source,js]
--------------------------------------------------
{
"query": {
"function_score": {
"query": { <1>
"match": {
"title": "your main query"
}
},
"functions": [{
"script_score": { <2>
"script": "doc['my_boost_field'].value"
}
}],
"score_mode": "multiply"
}
}
}
--------------------------------------------------
<1> The original query, now wrapped in a `function_score` query.
<2> This script returns the value in `my_boost_field`, which is then
multiplied by the query `_score` for each document.
|