一、先测试是否安装了ik分词器
先测试是否安装了ik分词器:
http://10.1.2.206:9200/_analyze?analyzer=standard&pretty=true&text=中华人民共和国
没有安装则如下:
tokens
0
token "中"
start_offset 0
end_offset 1
type "<IDEOGRAPHIC>"
position 1
1
token "华"
start_offset 1
end_offset 2
type "<IDEOGRAPHIC>"
position 2
2
token "人"
start_offset 2
end_offset 3
type "<IDEOGRAPHIC>"
position 3
3
token "民"
start_offset 3
end_offset 4
type "<IDEOGRAPHIC>"
position 4
4
token "共"
start_offset 4
end_offset 5
type "<IDEOGRAPHIC>"
position 5
5
token "和"
start_offset 5
end_offset 6
type "<IDEOGRAPHIC>"
position 6
6
token "国"
start_offset 6
end_offset 7
type "<IDEOGRAPHIC>"
position 7
注意:2.0一下版本需要加index
http://10.1.2.206:9200/your_index/_analyze?analyzer=standard&pretty=true&text=中华人民共和国
二、安装
[root@bogon es]# git clone https://github.com/medcl/elasticsearch-analysis-ik
[root@bogon es]# cd elasticsearch-analysis-ik
[root@bogon es]# git tag --查看版本号
[root@bogon es]# git checkout tags/{version}
[root@bogon es]# mvn clean
[root@bogon es]# mvn compile
[root@bogon es]# mvn package
1.拷贝和解压release下的文件: /elasticsearch-analysis-ik/target/releases/elasticsearch-analysis-ik-1.4.1-jar-with-dependencies.jar 到你的 elasticsearch 插件目录, 如: plugins/ik
2.拷贝config文件:/elasticsearch-analysis-ik/config/elasticsearch.yml中的内容拷贝到es的config下elasticsearch.yml中(最下方)、其余的(ik文件夹和logging.yml)也拷贝到es的config下
三、测试
http://10.1.2.206:9200/beijing(索引名字)/_analyze?analyzer=ik&pretty=true&text=%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD
tokens
0
token "中华人民共和国"
start_offset 0
end_offset 7
type "CN_WORD"
position 1
1
token "中华人民"
start_offset 0
end_offset 4
type "CN_WORD"
position 2
2
token "中华"
start_offset 0
end_offset 2
type "CN_WORD"
position 3
3
token "华人"
start_offset 1
end_offset 3
type "CN_WORD"
position 4
4
token "人民共和国"
start_offset 2
end_offset 7
type "CN_WORD"
position 5
5
token "人民"
start_offset 2
end_offset 4
type "CN_WORD"
position 6
6
token "共和国"
start_offset 4
end_offset 7
type "CN_WORD"
position 7
7
token "共和"
start_offset 4
end_offset 6
type "CN_WORD"
position 8
8
token "国"
start_offset 6
end_offset 7
type "CN_CHAR"
position 9