1、下载
https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v7.2.0
查找对应版本下载
我们下载6.8.2的
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.2/elasticsearch-analysis-ik-6.8.2.zip
2、解压下载到plugins目录下并解压
unzip elasticsearch-analysis-ik-6.8.2.zip
mv elasticsearch-analysis-ik-6.8.2 ik
3、安装完毕并重启启动es
jps
21660 Elasticsearch
kill -9 21660
./bin/elasticsearch -d
4、使用ik分词
IK分词的原理与测试
IK 的 ik_smart 和 ik_max_word 两种分词策略
默认分词
GET _analyze
{
"text": "共和国国歌"
}
结果
{
"tokens" : [
{
"token" : "共",
"start_offset" : 0,
"end_offset" : 1,
"type" : "<IDEOGRAPHIC>",
"position" : 0
},
{
"token" : "和",
"start_offset" : 1,
"end_offset" : 2,
"type" : "<IDEOGRAPHIC>",
"position" : 1
},
{
"token" : "国",
"start_offset" : 2,
"end_offset" : 3,
"type" : "<IDEOGRAPHIC>",
"position" : 2
},
{
"token" : "国",
"start_offset" : 3,
"end_offset" : 4,
"type" : "<IDEOGRAPHIC>",
"position" : 3
},
{
"token" : "歌",
"start_offset" : 4,
"end_offset" : 5,
"type" : "<IDEOGRAPHIC>",
"position" : 4
}
]
}
ik_smart 分词
GET _analyze
{
"analyzer":"ik_smart",
"text":"中华人民共和国中央人民政府万岁"
}
结果
{
"tokens" : [
{
"token" : "中华人民共和国",
"start_offset" : 0,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "中央人民政府",
"start_offset" : 7,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "万岁",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 2
}
]
}
ik_max_word分词
GET _analyze
{
"analyzer":"ik_max_word",
"text":"中华人民共和国中央人民政府万岁"
}
结果
{
"tokens" : [
{
"token" : "中华人民共和国",
"start_offset" : 0,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "中华人民",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "中华",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "华人",
"start_offset" : 1,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 3
},
{
"token" : "人民共和国",
"start_offset" : 2,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 4
},
{
"token" : "人民",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 5
},
{
"token" : "共和国",
"start_offset" : 4,
"end_offset" : 7,
"type" : "CN_WORD",
"position" : 6
},
{
"token" : "共和",
"start_offset" : 4,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 7
},
{
"token" : "国中",
"start_offset" : 6,
"end_offset" : 8,
"type" : "CN_WORD",
"position" : 8
},
{
"token" : "国",
"start_offset" : 6,
"end_offset" : 7,
"type" : "CN_CHAR",
"position" : 9
},
{
"token" : "中央人民政府",
"start_offset" : 7,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 10
},
{
"token" : "中央",
"start_offset" : 7,
"end_offset" : 9,
"type" : "CN_WORD",
"position" : 11
},
{
"token" : "人民政府",
"start_offset" : 9,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 12
},
{
"token" : "人民",
"start_offset" : 9,
"end_offset" : 11,
"type" : "CN_WORD",
"position" : 13
},
{
"token" : "民政",
"start_offset" : 10,
"end_offset" : 12,
"type" : "CN_WORD",
"position" : 14
},
{
"token" : "政府",
"start_offset" : 11,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 15
},
{
"token" : "万岁",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 16
},
{
"token" : "万",
"start_offset" : 13,
"end_offset" : 14,
"type" : "TYPE_CNUM",
"position" : 17
},
{
"token" : "岁",
"start_offset" : 14,
"end_offset" : 15,
"type" : "COUNT",
"position" : 18
}
]
}
最后修改于 2019-12-30 13:53:54
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

