1 Star 0 Fork 0

缠中说禅/elasticsearch-definitive-guide

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
75_Changing_similarities.asciidoc 2.19 KB
一键复制 编辑 原始数据 按行查看 历史

Changing Similarities

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)
        }
      }
  }
}
  1. The title field uses BM25 similarity.

  2. 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 BM25

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)
        }
      }
    }
  }
}
  1. Create a custom similarity called my_bm25, based on the built-in BM25 similarity.

  2. Disable field-length normalization. See [bm25-tunability].

  3. Field title uses the custom similarity my_bm25.

  4. 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.
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SFAC_hds/elasticsearch-definitive-guide.git
git@gitee.com:SFAC_hds/elasticsearch-definitive-guide.git
SFAC_hds
elasticsearch-definitive-guide
elasticsearch-definitive-guide
master

搜索帮助