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 ...
随机推荐
- Unity暂停游戏功能
关于暂停游戏功能的做法,网上的教程以及Unity官方发布的Demo都是通过把Time.timeScale设成0来实现的,然而这会导致一些蛋疼的问题,因为Time.timeScale是全局变量,改成0后 ...
- oracle填坑之PLSQL中文显示为问号
刚入坑oracle就遇到个坑. 坑描述: 系统:Windows7 oracle:同时安装,11g和12c(安装顺序,先装的12c然后装的11g) 坑:开始安装的12c用SQL Developer使用本 ...
- 使用K-means进行聚类,用calinski_harabaz_score评价聚类效果
代码如下: """ 下面的方法是用kmeans方法进行聚类,用calinski_harabaz_score方法评价聚类效果的好坏 大概是类间距除以类内距,因此这个值越大越 ...
- loadrunner参数化使用mysql数据源失败解决方法
操作系统:win7 在64位的操作系统上,如果你想要连接32位mysql,避免安装mysql connector/odbc 64位,否则即使配置ODBC数据源连接正常,但loadrunner无法正常调 ...
- 导入myeclipse的java源码查看不了的问题
导入之前自己的jar包后 ,可以正常使用了,但是发现按ctrl+鼠标左键查看不了源代码.attach source 来源后,还是没有效果. 先添加所要使用的jar包, 然后再添加源文件.最后终于显示成 ...
- 转发自:一像素 十大经典排序算法(动图演示)原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删
原链接:https://www.cnblogs.com/onepixel/articles/7674659.html 个人收藏所用 侵删 0.算法概述 0.1 算法分类 十种常见排序算法可 ...
- java面试题复习(四)
31.内部类可以引用它的外部类的私有成员吗? 可以,内部类对象可以访问创建它的外部类对象的成员 32.final关键字有哪些用法? 修饰类时该类不能被继承,修饰方法时,该方法不能被重写,修饰变量时表示 ...
- ThreadLocal总结
一.问题抛出 SimpleDateFormat是非线程安全的,在多线程情况下会遇见问题: public static void main(String[] args) { ExecutorServic ...
- MM-移动类型
链接:SAP移动类型 移动类型 备注 业务类型 SAP中事务代码 备注 101 采购订单收货.生产订单收货 收货 migo CO11N顶层处理移动类型\跨工厂收货 102 采购订单收货冲销 收货 ...
- abaqus2016安装过程中出现error:unable to add abaqus command directory to PATH variable
请问abaqus2016安装过程中出现error:unable to add abaqus command directory to PATH variable是什么原因,怎么解决啊,总是安装失败 这 ...