ES设置查询的相似度算法

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介:

similarity

Elasticsearch allows you to configure a scoring algorithm or similarity per field. The similaritysetting provides a simple way of choosing a similarity algorithm other than the default BM25, such as TF/IDF.

Similarities are mostly useful for text fields, but can also apply to other field types.

Custom similarities can be configured by tuning the parameters of the built-in similarities. For more details about this expert options, see the similarity module.

The only similarities which can be used out of the box, without any further configuration are:

BM25
The Okapi BM25 algorithm. The algorithm used by default in Elasticsearch and Lucene. See  Pluggable Similarity Algorithms for more information.
classic
The TF/IDF algorithm which used to be the default in Elasticsearch and Lucene. See  Lucene’s Practical Scoring Function for more information.
boolean
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.

The similarity can be set on the field level when a field is first created, as follows:

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "default_field": { 
          "type": "text"
        },
        "classic_field": {
          "type": "text",
          "similarity": "classic" 
        },
        "boolean_sim_field": {
          "type": "text",
          "similarity": "boolean" 
        }
      }
    }
  }
}

The default_field uses the BM25 similarity.

The classic_field uses the classic similarity (ie TF/IDF).

The boolean_sim_field uses the boolean similarity.

 

Default and Base Similarities

By default, Elasticsearch will use whatever similarity is configured as default. However, the similarity functions queryNorm() and coord() are not per-field. Consequently, for expert users wanting to change the implementation used for these two methods, while not changing the default, it is possible to configure a similarity with the name base. This similarity will then be used for the two methods.

You can change the default similarity for all fields in an index when it is created:

PUT /my_index
{
  "settings": {
    "index": {
      "similarity": {
        "default": {
          "type": "classic"
        }
      }
    }
  }
}

If you want to change the default similarity after creating the index you must close your index, send the follwing request and open it again afterwards:

PUT /my_index/_settings
{
  "settings": {
    "index": {
      "similarity": {
        "default": {
          "type": "classic"
        }
      }
    }
  }
}

from:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/index-modules-similarity.html


















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/7451929.html,如需转载请自行联系原作者


相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
4天前
|
算法 测试技术 C#
C++二分查找算法:包含每个查询的最小区间
C++二分查找算法:包含每个查询的最小区间
|
4天前
|
算法 Java C语言
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1 算法训练 区间k大数查询
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1 算法训练 区间k大数查询
18 0
|
4天前
|
算法
有史以来最全的图像相似度算法
有史以来最全的图像相似度算法
5 0
|
8月前
|
机器学习/深度学习 存储 算法
机器学习k近邻算法kd树实现优化查询
机器学习k近邻算法kd树实现优化查询
50 0
|
9月前
|
算法 JavaScript
W3Cschool编程实战JS脚本算法挑战:设置首字母大写算法挑战
返回一个字符串,确保字符串的每个单词首字母都大写,其余部分小写。
62 0
|
10月前
|
人工智能 自然语言处理 算法
基于知识图谱的电影知识问答系统:训练TF-IDF 向量算法和朴素贝叶斯分类器、在 Neo4j 中查询
基于知识图谱的电影知识问答系统:训练TF-IDF 向量算法和朴素贝叶斯分类器、在 Neo4j 中查询
基于知识图谱的电影知识问答系统:训练TF-IDF 向量算法和朴素贝叶斯分类器、在 Neo4j 中查询
|
算法 搜索推荐 数据格式
基于用户的协同过滤算法(及3种计算用户相似度的方法)
本文参考《推荐系统实践》中基于用户的协同过滤算法内容。基于老师上课讲解,自己实现了其中的代码,了解了整个过程。
230 0
|
算法
一天一个算法——>二叉搜索树的插入、查询、删除
一天一个算法——>二叉搜索树的插入、查询、删除
59 0
04【C语言 & 趣味算法】“抓交通肇事犯”问题。算法改进:设置“标识变量”,有效减少循环次数。
04【C语言 & 趣味算法】“抓交通肇事犯”问题。算法改进:设置“标识变量”,有效减少循环次数。
04【C语言 & 趣味算法】“抓交通肇事犯”问题。算法改进:设置“标识变量”,有效减少循环次数。
|
算法
基于A星和dijkstra算法的障碍物规避matlab仿真,可以设置行列数,随机产生障碍物
基于A星和dijkstra算法的障碍物规避matlab仿真,可以设置行列数,随机产生障碍物
165 0
基于A星和dijkstra算法的障碍物规避matlab仿真,可以设置行列数,随机产生障碍物