• ElasticSearch 进阶(一)


    一、ES之存储结构mapping解读

    ES之存储结构mapping解读

    3.1 字段数据类型

    3.1.1 文本类型

    文本族包括以下字段类型:

    • text,即用于全文本内容(如电子邮件正文或产品描述)的传统字段类型。
    • match_only_text 是 text 的空间优化变体,它禁用评分,并在需要位置的查询上执行较慢。它最适合为日志消息编制索引。

    text 字段接受以下参数:

    curl -XPOST http://localhost:9200/index/_mapping -H 'Content-Type:application/json' -d'
    {
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart"
            }
        }
    }'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    analyzerThe analyzer which should be used for the text field, both at index-time and at search-time (unless overridden by the search_analyzer). Defaults to the default index analyzer, or the standard analyzer.

    二、文本分析(Text analysis)

    2.1 Built-in analyzer reference

    2.1.1 Standard analyzer

    standard 分词器是默认的分词器,如果没有指定其它的分词器,则使用该分词器。
    它提供了grammar based tokenization(基于Unicode文本分割算法,如Unicode标准附录#29所述),并且适用于大多数语言。

    POST /_analyze
    {
      "analyzer": "standard",
      "text": "中华民族伟大复兴"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    standard 分词器接受以下参数:

    • max_token_length:
      最大令牌长度。如果看到的令牌超过了这个长度,则按max_token_length间隔对其进行分割。默认为255

    • stopwords
      预定义的停止词列表,如_english_,或包含停止词列表的数组。默认为_none_。

    • stopwords_path
      包含停止字的文件的路径。

    // 自定义分词器
    PUT /my-index-000001
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "my_english_analyzer": {
              "type": "standard",
              "max_token_length": 5,
              "stopwords": "_english_"
            }
          }
        }
      }
    }
    
    POST /my-index-000001/_analyze
    {
      "analyzer": "my_english_analyzer",
      "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    Standard analyzer 包括:

    Tokenizer

    • Standard Tokenizer

    Token Filters

    • Lower Case Token Filter
    • Stop Token Filter (disabled by default)

    2.2 Token filter reference

    如果您需要在配置参数之外定制标准分词器,那么您需要将其重新创建为定制分词器并修改它,通常是通过添加令牌过滤器。

    PUT /standard_example
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "rebuilt_standard": {
              "tokenizer": "standard",
              "filter": [
                "lowercase"       
              ]
            }
          }
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  • 相关阅读:
    图解LeetCode——754. 到达终点数字(难度:中等)
    Vue2或Vue3使用Pinia快速入门
    Part 1: Implementing the Set ADT
    【POJ No. 2777】 颜色统计 Count Color
    MATLAB 软件功能简介
    可编程数据平面(论文阅读)
    Python-文件
    2022CCPC桂林 E. Draw a triangle (gym104008E)
    【网络编程】从零开始搭建一个开源博客网站(云服务器+宝塔+WordPress)
    C语言数据结构算法之求出栈序列个数、判断出栈序列是否合法、求所有合法出栈序列、入栈次数、出栈次数、
  • 原文地址:https://blog.csdn.net/chinusyan/article/details/127425881