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引入案例遗留问题大揭秘

  1. GET /_search?q=2017

搜索的是_all field,document所有的field都会拼接成一个大串,进行分词
_all,2017,自然会搜索到 3 个 docuemnt

GET /_search?q=2017-01-01

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

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

date,会作为exact value去建立索引
GET /_search?q=post_date:2017,这个在这里不讲解,因为是es 5.2以后做的一个优化

3、测试分词器

GET /_analyze
{
  "analyzer": "standard",
  "text": "Text to analyze"
}
{
  "tokens" : [
    {
      "token" : "text",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "to",
      "start_offset" : 5,
      "end_offset" : 7,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "analyze",
      "start_offset" : 8,
      "end_offset" : 15,
      "type" : "<ALPHANUM>",
      "position" : 2
    }
  ]
}