首页 > 其他分享 >Elasticsearch - 直观了解查询( term、match、match_phrase和query_string)区别

Elasticsearch - 直观了解查询( term、match、match_phrase和query_string)区别

时间:2023-02-11 18:36:01浏览次数:62  
标签:term string text 查询 字段 phrase 分词 match

文章目录

 

一、term

term 查询语句不分词

1、term查询keyword字段

keyword字段不分词
term查询keyword字段,需要完全匹配

2、term查询text字段

text字段分词
term查询text字段,必须为text字段分词后中的某一个才行。如“我真帅”分词为[“我”,“真”,“帅”],term必须为“我”或“真”或“帅”,才能查到,而“我帅”、“真帅”不行。

二、match

match 查询语句分词

1、match查询keyword字段

keyword字段不分词
match查询keyword字段,需要完全匹配

2、match查询text字段

text字段分词
match查询text字段,只需要match分词结果中和text分词有匹配就可以查出。如“我真帅”分词为[“我”,“真”,“帅”],match的查询语句“真帅”被分词为[“真”,“帅”],其中“真”、“帅”能匹配上text字段的分词结果,所以能查出。

三、match_phrase

match_phrase 查询语句分词

1、match_phrase 查询keyword字段

keyword字段不分词
match_phrase 查询keyword字段,需要完全匹配

2、match_phrase 查询text字段

text字段分词
match_phrase 查询text字段,只需要match_phrase 分词结果中和text分词有匹配且查询语句必须包含在text分词结果中,同时顺序相同且连续,才可以查出。如“我真帅”分词为[“我”,“真”,“帅”,“真帅”],match_phrase 的查询语句“真帅”被分词为[“真帅”],其中“真帅”能匹配上text字段的分词结果,连续且顺序相同,所以能查出。

四、query_string

和match_phrase类似,唯一区别的是,分词只要匹配上即可。不需要连续,顺序还可以调换。

标签:term,string,text,查询,字段,phrase,分词,match
From: https://www.cnblogs.com/sunlong88/p/17112287.html

相关文章