官方demo https://github.com/medcl/elasticsearch-analysis-ik
安装ik分词器有2种方式
1、下载Elasticsearch对应版本的ik包,然后解压致Elasticsearch中。
- ik和ES的版本对应
- 下载对应版本的ik
- 解压
- 在ES的conf和plugins文件夹下各自新建一个analysis-ik的文件夹
- 将解压后以下文件中除config文件夹外的全部拷贝到plugins文件夹下的analysis-ik文件夹中
es中plugins最终结果
- 将解压后文件config文件夹内的全部文件拷贝到conf文件夹下的analysis-ik文件夹中
es中conf/analysis-ik的最终结果
2、linux中通过命令直接安装。
执行-plugin
安装
./bin/elasticsearch-plugin install https:
//github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.3/elasticsearch-analysis-ik-6.2.3.zip
|
最后重启ES
1.查找ES进程
ps -ef | grep elastic
2.杀掉ES进程
kill -9 2382(进程号)
3.重启ES
sh elasticsearch -d
验证ik分词器是否使用
1.通过Rest方式创建 index
【PUT】 http://ip:9200/index
2通过Rest方式创建 mapping
【POST】 http://ip:9200/index/fulltext/_mapping
请求头
Content-Type='Content-Type:application/json'
参数
{
"properties"
: {
"content"
: {
"type"
:
"text"
,
"analyzer"
:
"ik_max_word"
,
"search_analyzer"
:
"ik_max_word"
}
}
}
|
3.通过Rest方式插入一些数据
【POST】 http://ip:9200/index/fulltext/1
Content-Type='Content-Type:application/json'
参数
{
"content"
:
"美国留给伊拉克的是个烂摊子吗"
}
|
【POST】 http://ip:9200/index/fulltext/2
Content-Type='Content-Type:application/json'
参数
{
"content"
:
"公安部:各地校车将享最高路权"
|
【POST】 http://ip:9200/index/fulltext/3
Content-Type='Content-Type:application/json'
参数
{
"content"
:
"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
|
【POST】 http://ip:9200/index/fulltext/4
Content-Type='Content-Type:application/json'
参数
{
"content"
:
"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
}
|
4.通过Rest方式查询测试
【POST】 http://ip:9200/index/fulltext/_search
Content-Type='Content-Type:application/json'
参数
{
"query"
: {
"match"
: {
"content"
:
"中国"
}},
"highlight"
: {
"pre_tags"
: [
"<tag1>"
,
"<tag2>"
],
"post_tags"
: [
"</tag1>"
,
"</tag2>"
],
"fields"
: {
"content"
: {}
}
}
|
请求返回
{
"took"
:
14
,
"timed_out"
:
false
,
"_shards"
: {
"total"
:
5
,
"successful"
:
5
,
"failed"
:
0
},
"hits"
: {
"total"
:
2
,
"max_score"
:
2
,
"hits"
: [
{
"_index"
:
"index"
,
"_type"
:
"fulltext"
,
"_id"
:
"4"
,
"_score"
:
2
,
"_source"
: {
"content"
:
"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
},
"highlight"
: {
"content"
: [
"<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
]
}
},
{
"_index"
:
"index"
,
"_type"
:
"fulltext"
,
"_id"
:
"3"
,
"_score"
:
2
,
"_source"
: {
"content"
:
"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
},
"highlight"
: {
"content"
: [
"均每天扣1艘<tag1>中国</tag1>渔船 "
]
}
}
]
}
}
|