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

ES设置查询的相似度算法的更多相关文章

  1. 文本相似度算法——空间向量模型的余弦算法和TF-IDF

    1.信息检索中的重要发明TF-IDF TF-IDF是一种统计方法,TF-IDF的主要思想是,如果某个词或短语在一篇文章中出现的频率TF高,并且在其他文章中很少出现,则认为此词或者短语具有很好的类别区分 ...

  2. 文本相似度 余弦值相似度算法 VS L氏编辑距离(动态规划)

    设置n为字符串s的长度.("我是个小仙女") 设置m为字符串t的长度.("我不是个小仙女") 如果n等于0,返回m并退出.如果m等于0,返回n并退出.构造两个向 ...

  3. Atitit.列表页面and条件查询的实现最佳实践(1)------设置查询条件and提交查询and返回json数据

    Atitit.列表页面and条件查询的实现最佳实践(1)------设置查询条件and提交查询and返回json数据 1. 1. 配置条件字段@Conditional 1 1 2. 2. 配置条件字段 ...

  4. ES : 软件工程学的复杂度理论及物理学解释

    系统论里面总是有一些通用的专业术语 比如复杂度.熵.焓,复杂度专门独立出来,成为复杂度理论 文章摘抄于:<非线性动力学> 刘秉政 编著  5.5 复杂性及其测度 热力学的几个专业术语 熵. ...

  5. python结巴分词余弦相似度算法实现

    过余弦相似度算法计算两个字符串之间的相关度,来对关键词进行归类.重写标题.文章伪原创等功能, 让你目瞪口呆.以下案例使用的母词文件均为txt文件,两种格式:一种内容是纯关键词的txt,每行一个关键词就 ...

  6. ES 复合查询

    ES在查询过程中比较多遇到符合查询,既需要多个字段过滤也需要特殊情况处理,本文简单介绍几种查询组合方便快捷查询ES. bool布尔查询有一个或者多个布尔子句组成     filter 只过滤符合条件的 ...

  7. Spark/Scala实现推荐系统中的相似度算法(欧几里得距离、皮尔逊相关系数、余弦相似度:附实现代码)

    在推荐系统中,协同过滤算法是应用较多的,具体又主要划分为基于用户和基于物品的协同过滤算法,核心点就是基于"一个人"或"一件物品",根据这个人或物品所具有的属性, ...

  8. elasticsearch算法之词项相似度算法(一)

    一.词项相似度 elasticsearch支持拼写纠错,其建议词的获取就需要进行词项相似度的计算:今天我们来通过不同的距离算法来学习一下词项相似度算法: 二.数据准备 计算词项相似度,就需要首先将词项 ...

  9. es的查询、排序查询、分页查询、布尔查询、查询结果过滤、高亮查询、聚合函数、python操作es

    今日内容概要 es的查询 Elasticsearch之排序查询 Elasticsearch之分页查询 Elasticsearch之布尔查询 Elasticsearch之查询结果过滤 Elasticse ...

随机推荐

  1. windows下PTAM的编译

    前些日子在研究PTAM,以下首先说说PTAM的编译过程,我在XP几WIN7搭配vs2010中均已測试过,都能够执行. 首先下载编译PTAM所必须的库文件.下载地址我会给出 PTAM(PTAM.zip) ...

  2. javascript系列-class12.事件

    1.默认行为          什么是默认行为:默认行为就是浏览器自己触发的事件.比如:a链接的跳转,form提交时的跳转,鼠标右键跳转:   oncontexmenu当点击右键菜单的时候:   re ...

  3. HTML5学习笔记(三):标识文本的语义元素

    1.<time>元素:标注日期和时间 日期格式:YYYY-MM-DD,如2016-04-13: 时间格式(24小时制):HH-MM,如15:31: 最后,组合以上规则就可以制定具体的日期和 ...

  4. POJ 2388 基数排序

    这题可以直接nth_element过去 比如这样子 //By SiriusRen #include <cstdio> #include <algorithm> using na ...

  5. RAP开发入门-运行第一个HelloWorld(二)

    环境搭建好了之后我们就可以照惯例运行第一个helloworld程序了. (ps:这里钉几个资料吧 官网开发指导:http://help.eclipse.org/indigo/index.jsp?top ...

  6. UVa 10106 Product 【大数相乘】WA

    虽然是错的代码,但是还是想贴出来,最开始WA发现是没有考虑到乘积为0的情况,后来把a*0,0*a,a*0---0(若干个0),0--0(若干个0)*a都考虑进去了:可是还是WA,实在不懂先留在这儿. ...

  7. 编程范式(Programming Paradigm)-[ 程序员的编程世界观 ]

    编程范式(Programming Paradigm)是某种编程语言典型的编程风格或者说是编程方式.随着编程方法学和软件工程研究的深入,特别是OO思想的普及,范式(Paradigm)以及编程范式等术语渐 ...

  8. 立即调用函数(IIFE)

    定义: IIFE:立即调用的函数表达式,声明函数的同时立即调用这个函数. 语法: IIFE的常用写法:这两种写法的作用相同,只是表现形式不同而已,()只是起了自执行的作用 (function(){.. ...

  9. Ubuntu18.04解决鼠标移动到Gnome顶栏左上角窗口不能平铺( Activites Overview 界面),和应用程序扩展不好用问题。

    在用习惯了GNOME我们知道一个很好的功能就是通过鼠标移动到Gnome顶栏左上角后所有打开的窗口就会平铺在显示器上方便我们选不同的窗口(Activites Overview 界面),苹果MAC系统也有 ...

  10. Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS

    题目简单,不多解释. Code: #include<cstdio> #include<queue> using namespace std; const int maxn = ...