IK分词器 Elasticsearch插件地址:https://github.com/medcl/elasticsearch-analysis-ik
(注意下载对应的版本)
Versions
IK version ES version
master 7.x -> master
6.x 6.x
5.x 5.x
1.10.6 2.4.6
1.9.5 2.3.5
1.8.1 2.2.1
1.7.0 2.1.1
1.5.0 2.0.0
1.2.6 1.0.0
1.2.5 0.90.x
1.1.3 0.20.x
1.0.0 0.16.2 -> 0.19.0
#安装方法:将下载到的elasticsearch-analysis-ik-7.9.3.zip解压到/elasticsearch/plugins/ik
目录下即可。
#如果使用docker运行
docker cp /tmp/elasticsearch-analysis-ik-6.5.4.zip
elasticsearch:/usr/share/elasticsearch/plugins/
#进入容器
docker exec -it elasticsearch /bin/bash
mkdir /usr/share/elasticsearch/plugins/ik
cd /usr/share/elasticsearch/plugins/ik
unzip elasticsearch-analysis-ik-6.5.4.zip
#重启容器即可
docker restart elasticsearch
测试:
POST http://127.0.0.1:9200/itcast/_analyze
{
“analyzer”: “ik_max_word”,
“text”: “我是中国人”
}
结果:
{
tokens: [5]
0: {
token: "我"
start_offset: 0
end_offset: 1
type: "CN_CHAR"
position: 0
}-
1: {
token: "是"
start_offset: 1
end_offset: 2
type: "CN_CHAR"
position: 1
}-
2: {
token: "中国人"
start_offset: 2
end_offset: 5
type: "CN_WORD"
position: 2
}-
3: {
token: "中国"
start_offset: 2
end_offset: 4
type: "CN_WORD"
position: 3
}-
4: {
token: "国人"
start_offset: 3
end_offset: 5
type: "CN_WORD"
position: 4
}-
-
}