Elasticsearch 相似度设置、存储模块及实时搜索机制详解
1. 字段级相似度设置
自 Elasticsearch 0.90 版本起,我们能够为映射中的每个字段设置不同的相似度。例如,我们有用于索引博客文章的简单映射,存储在posts_no_similarity.json文件中:
{ "mappings" : { "post" : { "properties" : { "id" : { "type" : "long", "store" : "yes" }, "name" : { "type" : "string", "store" : "yes", "index" : "analyzed" }, "contents" : { "type" : "string", "store" : "no", "index" : "analyzed" } } } } }若要对name字段和contents字段使用 BM25 相似度模型,需扩展字段定义并添加similarity属性,值为所选相似度名称。修改后的映射存储在posts_similarity.json文件中,如下所示:
{ "mappings" : { "post" : { "properties" : { "id" : { "type" :