ES查询-match VS match_phrase
我们以一个查询的示例开始,我们在student这个type中存储了一些学生的基本信息,我们分别使用match和match_phrase进行查询。
首先,使用match进行检索,关键字是“He is”:
GET /test/student/_search
{
"query": {
"match": {
"description": "He is"
}
}
}
执行这条查询,得到的结果如下:
{
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": 0.2169777,
"hits": [
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.2169777,
"_source": {
"name": "februus",
"sex": "male",
"age": ,
"description": "He is passionate.",
"interests": "reading, programing"
}
},
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.16273327,
"_source": {
"name": "leotse",
"sex": "male",
"age": ,
"description": "He is a big data engineer.",
"interests": "reading, swiming, hiking"
}
},
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.01989093,
"_source": {
"name": "pascal",
"sex": "male",
"age": ,
"description": "He works very hard because he wanna go to Canada.",
"interests": "programing, reading"
}
},
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.016878016,
"_source": {
"name": "yolovon",
"sex": "female",
"age": ,
"description": "She is so charming and beautiful.",
"interests": "reading, shopping"
}
}
]
}
}
而当你执行match_phrase时:
GET /test/student/_search
{
"query": {
"match_phrase": {
"description": "He is"
}
}
}
结果如下:
{
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": 0.30685282,
"hits": [
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.30685282,
"_source": {
"name": "februus",
"sex": "male",
"age": ,
"description": "He is passionate.",
"interests": "reading, programing"
}
},
{
"_index": "test",
"_type": "student",
"_id": "",
"_score": 0.23013961,
"_source": {
"name": "leotse",
"sex": "male",
"age": ,
"description": "He is a big data engineer.",
"interests": "reading, swiming, hiking"
}
}
]
}
}
占的篇幅有点长,但是如果能基于此看清这两者之间的区别,那也是值得的。
我们分析一下这两者结果的差别:
1.非常直观的一点,对于同一个数据集,两者检索出来的结果集数量不一样;
2.对于match的结果,我们可以可以看到,结果的Document中description这个field可以包含“He is”,“He”或者“is”;
3.match_phrase的结果中的description字段,必须包含“He is”这一个词组;
4.所有的检索结果都有一个_score字段,看起来是当前这个document在当前搜索条件下的评分,而检索结果也是按照这个得分从高到低进行排序。
我们要想弄清楚match和match_phrase的区别,要先回到他们的用途:match是全文搜索,也就是说这里的搜索条件是针对这个字段的全文,只要发现和搜索条件相关的Document,都会出现在最终的结果集中,事实上,ES会根据结果相关性评分来对结果集进行排序,这个相关性评分也就是我们看到的_score字段;总体上看,description中出现了“He is”的Document的相关性评分高于只出现“He”或“is”的Document。(至于怎么给每一个Document评分,我们会在以后介绍)。
相关性(relevance)的概念在Elasticsearch中非常重要,而这个概念在传统关系型数据库中是不可想象的,因为传统数据库对记录的查询只有匹配或者不匹配。
那么,如果我们不想将我们的查询条件拆分,应该怎么办呢?这时候我们就可以使用match_phrase:
match_phrase是短语搜索,亦即它会将给定的短语(phrase)当成一个完整的查询条件。当使用match_phrase进行搜索的时候,你的结果集中,所有的Document都必须包含你指定的查询词组,在这里是“He is”。这看起来有点像关系型数据库的like查询操作。
ES查询-match VS match_phrase的更多相关文章
- ES查询-term VS match (转)
原文地址:https://blog.csdn.net/sxf_123456/article/details/78845437 elasticsearch 中term与match区别 term是精确查询 ...
- ES查询之刨根问底
昨天有一个需求,就是想要根据某个网关url做过滤,获取其下面所有的上下文nginx日志:如果直接"query":"https://XXX/YYY/ZZZ"发现有 ...
- Es查询工具使用
Kibana按照索引过滤数据 1.创建索引模式 2.查询索引中的数据 Es查询不返回数据 创建索引的时候指定mapping mappings={ "mappings": { &qu ...
- ElasticSearch 学习记录之ES查询添加排序字段和使用missing或existing字段查询
ES添加排序 在默认的情况下,ES 是根据文档的得分score来进行文档额排序的.但是自己可以根据自己的针对一些字段进行排序.就像下面的查询脚本一样.下面的这个查询是根据productid这个值进行排 ...
- .NetCore下ES查询驱动 PlainElastic .Net 升级官方驱动 Elasticsearch .Net
1.背景 由于历史原因,笔者所在的公司原有的ES查询驱动采用的是 PlainElastic.Net, 经过询问原来是之前PlainElastic.Net在园子里文档较多,上手比较容易,所以最初作者选用 ...
- ES查询语句
记录常用的es 查询 聚合 GET _cat / indices GET / p_ext_develop / _mapping / g GET / p_ext_develop / _analyze { ...
- es 查询更新操作
# es 查询更新操作# _*_ coding: utf-8 _*_ import time import datetime import pymysql from elasticsearch imp ...
- es查询--请求body
查询的JSON结构 普通查询 { "query": { # 查询条件 "match_all": {} //匹配所有文档, 所有 _score 为1.0 # &q ...
- Es查询结果集默认是10000,更新设置
Es查询结果集默认是10000,结果集大小是int,最大为21亿左右 PUT _all/_settings?preserve_existing=true { "index.max_resul ...
随机推荐
- maven教程全攻略
maven教程全攻略 我们在开发项目的过程中,会使用一些开源框架.第三方的工具等等,这些都是以jar包的方式被项目所引用,并且有些jar包还会依赖其他的jar包,我们同样需要添加到项目中,所有这些相关 ...
- 自定义panel实现,并实现item更改和移除动画。
原地址:https://www.cnblogs.com/yk250/p/10043694.html 无图无真相: 1,重写panel类(模拟实现一个竖直方向排列的panel,相当于默认的StackP ...
- 编译ijkplayer后直播无声音
打开:ijkplayer-android/config/module-lite.sh 文件: 你要把neyllow打开,默认是关闭的,如下: export COMMON_FF_CFG_FLAGS=&q ...
- CentOS 7 升级 Linux 内核
一.升级内核 1.更新仓库 yum -y update 2.用 ELRepo 仓库 rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org ...
- 【Nginx】实现负载均衡
负载均衡是什么? 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均衡的方式来分担服务器压力. 我 ...
- ios监听静音键和音量键事件
http://blog.csdn.net/slinloss/article/details/7870559
- 记数据库数据文件损坏恢复ORA-00376+ORA-01110
现象:业务平台无法登陆,日志报错为ORACLE的错误. 查看oracle日志的报错, ORA-00376: file 5 cannot be read at this time ORA-01110: ...
- [PHP+JS]微信卡券(潦草笔记,全代码,亲测通过)
群发卡券可以通过客服消息推送 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547 后端代码: define('A ...
- mysql for循环存储过程
DROP PROCEDURE IF EXISTS test_insert; DELIMITER ;; CREATE PROCEDURE test_insert () BEGIN DECLARE i i ...
- Django08-批量创建数据
通过views.py文件中创建 第1种方法循环创建数据, 这种方法不推荐,因为每一次循环都会连接一次数据库,效率较慢 def user_list(request): user_all = models ...