2016-03-02 04:51:47 -05:00
[[mapping-boost]]
2015-08-06 11:24:29 -04:00
=== `boost`
2016-03-02 04:51:47 -05:00
Individual fields can be _boosted_ automatically -- count more towards the relevance score
-- at query time, with the `boost` parameter as follows:
2015-08-06 11:24:29 -04:00
[source,js]
--------------------------------------------------
PUT my_index
{
"mappings": {
2017-12-14 11:47:53 -05:00
"_doc": {
2015-08-06 11:24:29 -04:00
"properties": {
"title": {
2016-03-18 12:01:27 -04:00
"type": "text",
2015-08-06 11:24:29 -04:00
"boost": 2 <1>
},
"content": {
2016-03-18 12:01:27 -04:00
"type": "text"
2015-08-06 11:24:29 -04:00
}
}
}
}
}
--------------------------------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2015-08-06 11:24:29 -04:00
<1> Matches on the `title` field will have twice the weight as those on the
`content` field, which has the default `boost` of `1.0`.
2016-03-02 04:51:47 -05:00
NOTE: The boost is applied only for term queries (prefix, range and fuzzy queries are not _boosted_).
2015-08-06 11:24:29 -04:00
2016-03-02 04:51:47 -05:00
You can achieve the same effect by using the boost parameter directly in the query, for instance the following query (with field time boost):
[source,js]
--------------------------------------------------
2016-04-29 10:42:03 -04:00
POST _search
2016-03-02 04:51:47 -05:00
{
2016-04-29 10:42:03 -04:00
"query": {
"match" : {
"title": {
"query": "quick brown fox"
}
2016-03-02 04:51:47 -05:00
}
}
}
--------------------------------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2016-03-02 04:51:47 -05:00
is equivalent to:
[source,js]
--------------------------------------------------
2016-04-29 10:42:03 -04:00
POST _search
2016-03-02 04:51:47 -05:00
{
2016-04-29 10:42:03 -04:00
"query": {
"match" : {
"title": {
"query": "quick brown fox",
"boost": 2
}
2016-03-02 04:51:47 -05:00
}
}
}
--------------------------------------------------
2016-05-09 09:42:23 -04:00
// CONSOLE
2016-03-02 04:51:47 -05:00
deprecated[5.0.0, index time boost is deprecated. Instead, the field mapping boost is applied at query time. For indices created before 5.0.0 the boost will still be applied at index time.]
2015-08-06 11:24:29 -04:00
[WARNING]
.Why index time boosting is a bad idea
==================================================
We advise against using index time boosting for the following reasons:
* You cannot change index-time `boost` values without reindexing all of your
documents.
* Every query supports query-time boosting which achieves the same effect. The
difference is that you can tweak the `boost` value without having to reindex.
* Index-time boosts are stored as part of the <<norms,`norm`>>, which is only one
byte. This reduces the resolution of the field length normalization factor
which can lead to lower quality relevance calculations.
2016-03-18 12:01:27 -04:00
==================================================