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"
        }
    }
}'
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": "中华民族伟大复兴"
}

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."
}

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"       
          ]
        }
      }
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值