1. analysis-ik安装
1). 从 https://github.com/medcl/elasticsearch-analysis-ik ,下载 elasticsearch-analysis-ik-master.zip
2). 解压后,
cd elasticsearch-analysis-ik-master
/usr/local/maven/bin/mvn package
.... wait 5-6分钟
编译成功后,
拿到target/releases/下的zip包,上传到服务器上
上config目录的ik文件夹到服务器上
3). 安装插件
/usr/share/elasticsearch/bin/plugin -i analysis-ik -u file:///soft/elasticsearch-analysis-ik-1.3.0.zip (本地安装)
/usr/share/elasticsearch/bin/plugin -i analysis-ik ftp://10.104.16.43/es/analysis-ik/elasticsearch-analysis-ik-1.3.0.zip (内网安装)
scp -r ./ik $ip:/etc/elasticsearch/
echo 'index.analysis.analyzer.ik.type : "ik"' >> /etc/elasticsearch/elasticsearch.yml
4).重启集群
2. analysis-ik测试
导入测试数据
- [root@VM_16_43_centos analysis-ik]# cat iktest.sh
#1.creat a index
curl -XPUT http://localhost:9200/iktest
#2.create a mapping
curl -XPOST http://localhost:9200/iktest/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"indexAnalyzer": "ik",
"searchAnalyzer": "ik",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"indexAnalyzer": "ik",
"searchAnalyzer": "ik",
"include_in_all": "true",
"boost": 8
}
}
}
}'
#3.iktest index some docs
curl -XPOST http://localhost:9200/iktest/fulltext/1-d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/iktest/fulltext/2-d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/iktest/fulltext/3-d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/iktest/fulltext/4-d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
[root@VM_16_43_centos analysis-ik]# sh iktest.sh
{"acknowledged":true}
{"acknowledged":true}
{"_index":"iktest","_type":"fulltext","_id":"1","_version":1,"created":true}
{"_index":"iktest","_type":"fulltext","_id":"2","_version":1,"created":true}
{"_index":"iktest","_type":"fulltext","_id":"3","_version":1,"created":true}
{"_index":"iktest","_type":"fulltext","_id":"4","_version":1,"created":true}
查询数据
1)搜索“男子”

2) 搜索“公安”
