ik分词器github网址:https://github.com/medcl/elasticsearch-analysis-ik
可参考该网页内容进行安装
1、获取分词的依赖包
通过git clone https://github.com/medcl/elasticsearch-analysis-ik,下载分词器源码
2、进入源码目录,将代码进行打包
打包需要用到jdk,故在安装ik分词器之前需要安装jdk
mvn clean package
以上命令进行打包
在当前目录下生成了target目录,打包好的资源都在该目录下
3、拷贝打包好的资源至ES插件目录下
cp target/releases/elasticsearch-analysis-ik-{version}.zip your-es-root/plugins/ik
去到your-es-root/plugins/ik目录,解压资源包
unzip elasticsearch-analysis-ik-{version}.zip
4、重启ES
5、测试ik分词器是否安装成功
1、创建一个索引,名为index。
curl -XPUT http://localhost:9200/index
2、为索引index创建mapping。
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik"
},
"properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
}'
3、测试
curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"世界如此之大"
}'
显示结果如下:
{
"tokens" : [ {
"token" : "text",
"start_offset" : 4,
"end_offset" : 8,
"type" : "ENGLISH",
"position" : 1
}, {
"token" : "世界",
"start_offset" : 11,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 2
}, {
"token" : "如此",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "之大",
"start_offset" : 15,
"end_offset" : 17,
"type" : "CN_WORD",
"position" : 4
} ]
}