安装步骤:
一、参照官方文档安装IK分词器
1、直接到https://github.com/medcl/elasticsearch-analysis-ik/releases下载对应版本zip包
解压到elasticsearch的plugin目录下
unzip elasticsearch-analysis-ik-5.5.1.zip
2、使用elasticsearch-plugin命令安装
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip
重新启动elasticsearch
systemctl restart elasticsearch.service
测试一下:
1、创建索引
curl -XPUT http://localhost:9200/index
2、创建一个映射
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
3、创建文档
curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}’
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}’
curl -XPOST 192.168.1.156:9200/test_index/fulltext/3 -d'
{"content":"公安部:各地校车将享最高路权"}’
4、查询
curl -XPOST 192.168.1.156:9200/test_index/fulltext/_search -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}’
查询结果如下:
{
- "took": 91,
- "timed_out": false,
参考资料:
官方文档:https://github.com/medcl/elasticsearch-analysis-ik