The similarity algorithm can be set on a per-field basis. It’s just a matter of specifying the chosen algorithm in the field’s mapping:
PUT /my_index
{
"mappings": {
"doc": {
"properties": {
"title": {
"type": "string",
"similarity": "BM25" (1)
},
"body": {
"type": "string",
"similarity": "default" (2)
}
}
}
}
The title
field uses BM25 similarity.
The body
field uses the default similarity (see [practical-scoring-function]).
Currently, it is not possible to change the similarity
mapping for an
existing field. You would need to reindex your data in order to do that.
Configuring a similarity is much like configuring an analyzer. Custom similarities can be specified when creating an index. For instance:
PUT /my_index
{
"settings": {
"similarity": {
"my_bm25": { (1)
"type": "BM25",
"b": 0 (2)
}
}
},
"mappings": {
"doc": {
"properties": {
"title": {
"type": "string",
"similarity": "my_bm25" (3)
},
"body": {
"type": "string",
"similarity": "BM25" (4)
}
}
}
}
}
Create a custom similarity called my_bm25
, based on the built-in BM25
similarity.
Disable field-length normalization. See [bm25-tunability].
Field title
uses the custom similarity my_bm25
.
Field body
uses the built-in similarity BM25
.
Tip
|
A custom similarity can be updated by closing the index, updating the index settings, and reopening the index. This allows you to experiment with different configurations without having to reindex your documents. |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。