一、插入数据
首先存入一条数据 i like eating and kuing 默认分词器应该将内容分为 “i” “like” “eating” “and” “kuing”
二、查询
2.1 QueryBuilders.matchQuery(“supplierName”,param)
会将搜索词分词,再与目标查询字段进行匹配,若分词中的任意一个词与目标字段匹配上,则可查询到。
param = “i” 可查出i
param = “i li” 可查出
param = “i like” 可查出
param = “i like eat” 可查出
param = “and” 可查出
param = “kuing” 可查出
param = "ku" 查不出
param = "li" 查不出
param = "eat" 查不出
param = “i like eating and kuing” 查出
2.2 QueryBuilders.matchPhraseQuery(“supplierName”,param)
默认使用 match_phrase 时会精确匹配查询的短语,需要全部单词和顺序要完全一样,标点符号除外。
param = “i” 可查出i
param = “i li” 查不出
param = “i like” 可查出
param = “i like eat” 查不出
param = “and” 可查出
param = “kuing” 可查出
param = "ku" 查不出
param = "li" 查不出
param = "eat" 查不出
param = “i like eating and kuing” 查出
2.3 QueryBuilders.matchPhrasePrefixQuery(“supplierName”,param)
match_phrase_prefix 和 match_phrase 用法是一样的,区别就在于它允许对最后一个词条前缀匹配。以上节的数据为例,查询 I like sw 就能匹配到
param = “i” 可查出i
param = “i li” 可查出
param = “i like” 可查出
param = “i like eat” 可查出
param = “and” 可查出
param = “kuing” 可查出
****param = "ku" 可查出***
**param = "li" 可查出
param = "eat" 可查出***
param = “i like eating and kuing” 查出
2.4 QueryBuilders.termQuery(“supplierName”,param)
而term query,输入的查询内容是什么,就会按照什么去查询,并不会解析查询内容,对它分词。
param = “i” 可查出i
param = “i li” 查不出
param = “i like” 查不出
param = “i like eat” 查不出
param = “and” 可查出
param = “kuing” 可查出
****param = "ku" 查不出***
**param = "li" 查不出
param = "eat" 查不出***
param = “i like eating and kuing” 查不出