es查询term,match,match_phase,query_string的区别

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了es查询term,match,match_phase,query_string的区别相关的知识,希望对你有一定的参考价值。

参考技术A match :模糊匹配,需要指定字段名,但是输入会进行分词,比如"hello world"会进行拆分为hello和world,然后匹配,如果字段中包含hello或者world,或者都包含的结果都会被查询出来,也就是说match是一个部分匹配的模糊查询。查询条件相对来说比较宽松。

term : 这种查询和match在有些时候是等价的,比如我们查询单个的词hello,那么会和match查询结果一样,但是如果查询"hello world",结果就相差很大,因为这个输入不会进行分词,就是说查询的时候,是查询字段分词结果中是否有"hello world"的字样,而不是查询字段中包含"hello world"的字样,elasticsearch会对字段内容进行分词,"hello world"会被分成hello和world,不存在"hello world",因此这里的查询结果会为空。这也是term查询和match的区别。

match_phase :会对输入做分词,但是需要结果中也包含所有的分词,而且顺序要求一样。以"hello world"为例,要求结果中必须包含hello和world,而且还要求他们是连着的,顺序也是固定的,hello that word不满足,world hello也不满足条件。

query_string :和match类似,但是match需要指定字段名,query_string是在所有字段中搜索,范围更广泛。

es查询和更新


GET /my_test*/_search

"query":
"bool":
"must": [

"term":
"root_id": 5

,

"match":
"sub_id": 0

,

"match":
"remote_address" : "69.246.123.214"


],
"must_not": [
"match": "root_name": "直播"
]


POST /my_test*/doc/_update_by_query?conflicts=proceed

"query":
"bool":
"must": [

"term":
"root_id": 5

,

"match":
"sub_id": 0

,

"match":
"remote_address": "69.246.123.214"


],
"must_not": [

"match":
"root_name": "直播"


]

,
"script":
"lang": "painless",
"source": "ctx._source.root_name = params.live_name",
"params":
"live_name": "直播"


以上是关于es查询term,match,match_phase,query_string的区别的主要内容,如果未能解决你的问题,请参考以下文章

es查询term,match,match_phase,query_string的区别

es的query查询(term,prefix,exists,match,matchprase,range)

git,es的基本查询,组合查询,mapping映射,i分词,term和match

git,es的基本查询,组合查询,mapping映射,i分词,term和match

ES文档级查询匹配限制

es match和term的区别