38、初识搜索引擎_query string的分词以及mappi

2020-01-06  本文已影响0人  拉提娜的爸爸

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,建立倒排索引

什么时query string?

我们要搜索这个document对应的index,搜索文本是"hello me",这个搜索文本就是query string,是紧跟在_search后的,如:_search?field:xxx
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引入案例遗留问题大揭秘

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
    }
  ]
}

这个语法就是测试分词器,解释:
analyzer:分词器类型
text:用于测试各类分词器的内容。
结果:显示分词器对内容的分词结果。

上一篇 下一篇

猜你喜欢

热点阅读