0
点赞
收藏
分享

微信扫一扫

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

文章目录

  • 一、term
  • 1、term查询keyword字段
  • 2、term查询text字段
  • 二、match
  • 1、match查询keyword字段
  • 2、match查询text字段
  • 三、match_phrase
  • 1、match_phrase 查询keyword字段
  • 2、match_phrase 查询text字段
  • 四、query_string

 

一、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类似,唯一区别的是,分词只要匹配上即可。不需要连续,顺序还可以调换。

举报

相关推荐

es中的match,term,match_phrase

0 条评论