ElasticSearch (6) – 中文分词器ik-analyzer
安装方法
1. 去到ElasticSeach / bin 路径
cd elasticsearch/bin
2. 安装插件:IK分词器
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.0/elasticsearch-analysis-ik-7.12.0.zip
3. 安装完毕了需要重启ElasticSearch
基础知识
IK分词器包含两种analyzer,一般用ik_max_word
ik_max_word:会将文本做最细粒度的拆分
ik_smart:会做最粗粒度的拆分
ik_max_word 和 ik_smart 什么区别?
ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合,适合 Term Query;
ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”,适合 Phrase 查询。
# ik_max_word分词测试
GET /_analyze
{
"text": "您好胖仔哈哈哈",
"analyzer": "ik_smart"
}
# 响应如下:
{
"tokens" : [
{
"token" : "您好",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "胖仔",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "哈哈哈",
"start_offset" : 4,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 2
}
]
}
# ik_max_word分词测试
GET /_analyze
{
"text": "我和我的祖国",
"analyzer": "ik_max_word"
}
# 响应如下:
{
"tokens": [
{
"token": "我",
"start_offset": 0,
"end_offset": 1,
"type": "CN_CHAR",
"position": 0
},
{
"token": "和我",
"start_offset": 1,
"end_offset": 3,
"type": "CN_WORD",
"position": 1
},
{
"token": "的",
"start_offset": 3,
"end_offset": 4,
"type": "CN_CHAR",
"position": 2
},
{
"token": "祖国",
"start_offset": 4,
"end_offset": 6,
"type": "CN_WORD",
"position": 3
}
]
}
![]()
Facebook评论