2015-08-06 23:24:29 +08:00
|
|
|
[[similarity]]
|
|
|
|
=== `similarity`
|
|
|
|
|
|
|
|
Elasticsearch allows you to configure a scoring algorithm or _similarity_ per
|
|
|
|
field. The `similarity` setting provides a simple way of choosing a similarity
|
2019-08-30 04:26:35 +08:00
|
|
|
algorithm other than the default `BM25`, such as `boolean`.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
2016-03-19 00:01:27 +08:00
|
|
|
Similarities are mostly useful for <<text,`text`>> fields, but can also apply
|
|
|
|
to other field types.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
2016-01-20 16:32:51 +08:00
|
|
|
Custom similarities can be configured by tuning the parameters of the built-in
|
2015-08-06 23:24:29 +08:00
|
|
|
similarities. For more details about this expert options, see the
|
|
|
|
<<index-modules-similarity,similarity module>>.
|
|
|
|
|
|
|
|
The only similarities which can be used out of the box, without any further
|
|
|
|
configuration are:
|
|
|
|
|
|
|
|
`BM25`::
|
2020-08-17 21:44:24 +08:00
|
|
|
The {wikipedia}/Okapi_BM25[Okapi BM25 algorithm]. The
|
2020-05-19 23:04:53 +08:00
|
|
|
algorithm used by default in {es} and Lucene.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
2017-03-28 22:17:23 +08:00
|
|
|
`boolean`::
|
2020-05-19 23:04:53 +08:00
|
|
|
A simple boolean similarity, which is used when full-text ranking is not needed
|
|
|
|
and the score should only be based on whether the query terms match or not.
|
|
|
|
Boolean similarity gives terms a score equal to their query boost.
|
2017-03-28 22:17:23 +08:00
|
|
|
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
|
|
The `similarity` can be set on the field level when a field is first created,
|
|
|
|
as follows:
|
|
|
|
|
2019-09-06 22:55:16 +08:00
|
|
|
[source,console]
|
2015-08-06 23:24:29 +08:00
|
|
|
--------------------------------------------------
|
2020-07-28 02:46:39 +08:00
|
|
|
PUT my-index-000001
|
2015-08-06 23:24:29 +08:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 22:13:52 +08:00
|
|
|
"properties": {
|
|
|
|
"default_field": { <1>
|
|
|
|
"type": "text"
|
|
|
|
},
|
|
|
|
"boolean_sim_field": {
|
|
|
|
"type": "text",
|
|
|
|
"similarity": "boolean" <2>
|
2015-08-06 23:24:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 22:55:16 +08:00
|
|
|
|
2016-10-27 16:32:01 +08:00
|
|
|
<1> The `default_field` uses the `BM25` similarity.
|
2018-04-03 22:45:25 +08:00
|
|
|
<2> The `boolean_sim_field` uses the `boolean` similarity.
|