一、Versions
ES Version: 2.1.1
IK Version: 1.6.2
說明:ES和IK的版本一定要相互兼容,具體兼容性可以查看下面的git說明
二、Install
- IK的下載:https://github.com/medcl/elasticsearch-analysis-ik
裏面附有安裝步驟可以參考,本步驟是略作補充和說明 - compile
mvn package
說明:這個使用mvn命令時很可能會出問題,建議使用工具如IDEA等打包
複製 target/releases/elasticsearch-analysis-ik-{version}.zip
to your-es-root/plugins/ik,將zip包解壓
說明:僅將zip包裏的文件放到ik文件夾中 - 配置config文件
將項目中config文件下的ik文件夾複製到your-es-root/config -
配置elasticsearch.yml
在elasticsearch.yml文件的最後添加配置(最簡單的配置):
index
:
analysis
:
analyzer
:
ik
:
type:
custom
tokenizer:
ik_max_word
|
-
restart ES
三、Quick Example
(以下大部分摘抄github中的步驟,不同的地方會做標紅)可以使用chrome的插件postman,非常好用
-
創建index
-
創建mapping(此處與github上不同)
curl
-XPOST http:
{
"fulltext" :
{
"_all" :
{
"analyzer" : "ik" ,
"search_analyzer" : "ik_max_word" ,
"term_vector" : "no" ,
"store" : "false"
},
"properties" :
{
"content" :
{
"type" : "string" ,
"store" : "no" ,
"term_vector" : "with_positions_offsets" ,
"analyzer" : "ik" ,
"search_analyzer" : "ik_max_word" ,
"include_in_all" : "true" ,
"boost" : 8
}
}
}
}
|
-
添加文檔
curl
-XPOST http:
{ "content" : "美國留給伊拉克的是個爛攤子嗎" }
'
curl
-XPOST http:
{ "content" : "公安部:各地校車將享最高路權" }
'
curl
-XPOST http:
{ "content" : "中韓漁警衝突調查:韓警平均每天扣1艘中國漁船" }
'
curl
-XPOST http:
{ "content" : "中國駐洛杉磯領事館遭亞裔男子槍擊
嫌犯已自首" }
'
|
-
查詢
curl
-XPOST http:
{
"query" :
{ "term" :
{ "content" : "中國" }},
"highlight" :
{
"pre_tags" :
[ "<tag1>" , "<tag2>" ],
"post_tags" :
[ "</tag1>" , "</tag2>" ],
"fields" :
{
"content" :
{}
}
}
}
'
|
-
結果
四、其他
參考github上的相關說明:https://github.com/medcl/elasticsearch-analysis-ik