query string的分词以及mapping引入案例遗留问题

query string的分词以及mapping引入案例遗留问题

1、query string分词

query string必须以和index建立时相同的analyzer进行分词
query string对exact value和full text的区别对待

date:exact value
_all:full text

比如我们有一个document,其中有一个field,包含的value是:hello you and me,建立倒排索引
我们要搜索这个document对应的index,搜索文本是hell me,这个搜索文本就是query string
query string,默认情况下,es会使用它对应的field建立倒排索引时相同的分词器去进行分词和normalization,只有这样,才能实现正确的搜索

我们建立倒排索引的时候,将dogs –> dog,结果你搜索的时候,还是一个dogs,那不就搜索不到了吗?所以搜索的时候,那个dogs也必须变成dog才行。才能搜索到。

知识点:不同类型的field,可能有的就是full text,有的就是exact value

post_date 类型是date:分词 exact value
_all:类型是:full text,分词,normalization

2、mapping引入案例遗留问题大揭秘

GET /_search?q=2017

搜索的是_all field,document所有的field都会拼接成一个大串,进行分词

2017-01-02 my second article this is my second article in this website 11400

所建立的倒排索引:

数据 doc1 doc2 doc3
2017 * * *
01 *
02 *
03 *

_all,2017,自然会搜索到3个docuemnt

GET /_search?q=2017-01-01

_all,2017-01-01,query string会用跟建立倒排索引一样的分词器去进行分词

2017
01
01

GET /_search?q=post_date:2017-01-01

date,会作为exact value去建立索引

数据 doc1 doc2 doc3
2017-01-01 *
2017-01-02 *
2017-01-03 *

post_date:2017-01-01,2017-01-01,doc1一条document

GET /_search?q=post_date:2017,这个在这里不讲解,因为是es 5.2以后做的一个优化 , 默认搜索出来一条

3、测试分词器

GET /_analyze
{
“analyzer”: “standard”,
“text”: “Text to analyze”
}

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • © 2020 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信