请注意:
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
更改相似度编辑
相似度算法可以按字段指定, 只需在映射中为不同字段选定即可:
PUT /my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "title": {
          "type":       "string",
          "similarity": "BM25" 
        },
        "body": {
          "type":       "string",
          "similarity": "default" 
        }
      }
  }
}
  | |
  | 
目前,Elasticsearch 不支持更改已有字段的相似度算法 similarity 映射,只能通过为数据重新建立索引来达到目的。
配置 BM25编辑
配置相似度算法和配置分析器很相似, 自定义相似度算法可以在创建索引时指定,例如:
PUT /my_index
{
  "settings": {
    "similarity": {
      "my_bm25": { 
        "type": "BM25",
        "b":    0 
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "title": {
          "type":       "string",
          "similarity": "my_bm25" 
        },
        "body": {
          "type":       "string",
          "similarity": "BM25" 
        }
      }
    }
  }
}
创建一个基于内置   | |
禁用字段长度规范化(field-length normalization)。参见 调试 BM25 。  | |
  | |
字段   | 
自定义的相似度算法可以通过关闭索引,更新索引设置,开启索引这个过程进行更新。这样可以无须重建索引又能试验不同的相似度算法配置。
Getting Started Videos
备份地址:http://www.lvesu.com/blog/es/changing-similarities.html