elasticsearch分词器

内置分词器

  • Standard Analyzer - 默认分词器,英文按单词词切分,并小写处理
  • Simple Analyzer - 按照单词切分(符号被过滤), 小写处理
  • Stop Analyzer - 小写处理,停用词过滤(the,a,is)
  • Whitespace Analyzer - 按照空格切分,不转小写
  • Keyword Analyzer - 不分词,直接将输入当作输出

内置分词器测试

标准分词器:按照单词分词 英文统一转为小写 过滤标点符号 中文单字分词

java 复制代码
POST /_analyze
{
  "analyzer": "standard",
  "text": "this is a , good Man 中华人民共和国"
}

Simple 分词器:英文按照单词分词 英文统一转为小写 去掉符号 中文按照空格进行分词

java 复制代码
POST /_analyze
{
  "analyzer": "simple",
  "text": "this is a , good Man 中华人民共和国"
}

Whitespace 分词器:中文 英文 按照空格分词 英文不会转为小写 不去掉标点符号

java 复制代码
POST /_analyze
{
  "analyzer": "whitespace",
  "text": "this is a , good Man"
}

创建索引设置分词

复制代码
PUT /索引名
{
  "settings": {},
  "mappings": {
    "properties": {
      "title":{
        "type": "text",
        "analyzer": "standard" //显示指定分词器
      }
    }
  }
}

中文分词器

在ES中支持中文分词器非常多 如 smartCNIK 等,推荐的就是 IK分词器

IK分词器的版本要你安装ES的版本一致

复制代码
1. 下载对应版本
- [es@linux ~]$ wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.0/elasticsearch-analysis-ik-7.14.0.zip

# 2. 解压
- [es@linux ~]$ unzip elasticsearch-analysis-ik-6.2.4.zip #先使用yum install -y unzip

# 3. 移动到es安装目录的plugins目录中
- [es@linux ~]$ ls elasticsearch-6.2.4/plugins/
 [es@linux ~]$ mv elasticsearch elasticsearch-6.2.4/plugins/
 [es@linux ~]$ ls elasticsearch-6.2.4/plugins/
   elasticsearch
 [es@linux ~]$ ls elasticsearch-6.2.4/plugins/elasticsearch/
  commons-codec-1.9.jar    config                               httpclient-4.5.2.jar    plugin-descriptor.properties
  commons-logging-1.2.jar  elasticsearch-analysis-ik-6.2.4.jar  httpcore-4.4.4.jar
  
# 4. 重启es生效

# 5. 本地安装ik配置目录为  
- es安装目录中/plugins/analysis-ik/config/IKAnalyzer.cfg.xml

IK有两种颗粒度的拆分:

  • ik_smart: 会做最粗粒度的拆分
  • ik_max_word: 会将文本做最细粒度的拆分(分词数更多)
相关推荐
Elasticsearch40 分钟前
为上下文工程构建高效的数据库检索工具
elasticsearch
武子康1 小时前
大数据-243 离线数仓 - 实战电商核心交易增量导入(DataX - HDFS - Hive 分区
大数据·后端·apache hive
代码匠心2 天前
从零开始学Flink:Flink SQL四大Join解析
大数据·flink·flink sql·大数据处理
武子康3 天前
大数据-242 离线数仓 - DataX 实战:MySQL 全量/增量导入 HDFS + Hive 分区(离线数仓 ODS
大数据·后端·apache hive
Elasticsearch3 天前
需要知道某个同义词是否实际匹配了你的 Elasticsearch 查询吗?
elasticsearch
SelectDB4 天前
易车 × Apache Doris:构建湖仓一体新架构,加速 AI 业务融合实践
大数据·agent·mcp
武子康4 天前
大数据-241 离线数仓 - 实战:电商核心交易数据模型与 MySQL 源表设计(订单/商品/品类/店铺/支付)
大数据·后端·mysql
IvanCodes4 天前
一、消息队列理论基础与Kafka架构价值解析
大数据·后端·kafka
武子康5 天前
大数据-240 离线数仓 - 广告业务 Hive ADS 实战:DataX 将 HDFS 分区表导出到 MySQL
大数据·后端·apache hive
洛森唛6 天前
ElasticSearch查询语句Query String详解:从入门到精通
后端·elasticsearch