Elasticsearch5.5.1安裝IK中文分詞器
安裝步驟:
一、參照官方文件安裝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
{
"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