标准分词器:按照单词分词 英文统一转为小写 过滤标点符号 中文单字分词
- POST /_analyze
- {
- "analyzer": "standard",
- "text": "this is a , good Man 中华人民共和国"
- }
Simple 分词器:英文按照单词分词 英文统一转为小写 去掉符号 中文按照空格进行分词
- POST /_analyze
- {
- "analyzer": "simple",
- "text": "this is a , good Man 中华人民共和国"
- }
Whitespace 分词器:中文 英文 按照空格分词 英文不会转为小写 不去掉标点符号
- POST /_analyze
- {
- "analyzer": "whitespace",
- "text": "this is a , good Man"
- }
创建索引设置分词
- PUT /索引名
- {
- "settings": {},
- "mappings": {
- "properties": {
- "title":{
- "type": "text",
- "analyzer": "standard" //显示指定分词器
- }
- }
- }
- }
在ES中支持中文分词器非常多 如 smartCN、IK 等,推荐的就是 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: 会将文本做最细粒度的拆分(分词数更多)