美文网首页
38、初识搜索引擎_query string的分词以及mappi

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

作者: 拉提娜的爸爸 | 来源:发表于2020-01-06 16:14 被阅读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引入案例遗留问题大揭秘

    • GET /_search?q=2017:搜索的是_all field,document所有的field都会拼接成一个大串,进行分词,在这些_all field中找到3个2017,所以,自然会搜到3个结果.
    • GET /_search?q=2017-01-01:_all,2017-01-01,query string会用跟建立倒排索引一样的分词器去进行分词,这个搜索字符会被分为 2017,01,01,那么一样找到了3个2017,所以有3个结果。
    • GET /_search?q=post_date:2017-01-01:其中'post_date'的类型时date,date会作为exact value去建立索引,所以,符合2017-01-01这条信息的就只有一条数据,所以返回1个结果。
    • 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
        }
      ]
    }
    

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

    相关文章

      网友评论

          本文标题:38、初识搜索引擎_query string的分词以及mappi

          本文链接:https://www.haomeiwen.com/subject/kqykactx.html