Elasticsearch 默認是帶分詞器了,對英文是按固定的英文的空格,或者「-」進行分詞,可是對中文分詞是一個一個字進行分詞。git
分詞測試地址:github
http://localhost:9200/_analyze?analyzer=standard&pretty=true&text=超級管理員elasticsearch
{ "tokens" : [ { "token" : "超", "start_offset" : 0, "end_offset" : 1, "type" : "<IDEOGRAPHIC>", "position" : 0 }, { "token" : "級", "start_offset" : 1, "end_offset" : 2, "type" : "<IDEOGRAPHIC>", "position" : 1 }, { "token" : "管", "start_offset" : 2, "end_offset" : 3, "type" : "<IDEOGRAPHIC>", "position" : 2 }, { "token" : "理", "start_offset" : 3, "end_offset" : 4, "type" : "<IDEOGRAPHIC>", "position" : 3 }, { "token" : "員", "start_offset" : 4, "end_offset" : 5, "type" : "<IDEOGRAPHIC>", "position" : 4 } ] }
IK分詞器對應ElasticSearch版本以下:IK分詞器下載地址:https://github.com/medcl/elasticsearch-analysis-ik測試
因此IK要下載1.10.6版本的命令行
IK解壓後進入目錄下3d
在該目錄下打開命令行窗口進行MAVEN打包:mvn packagecode
把\target\releases\elasticsearch-analysis-ik-1.10.6.zip解壓,把解壓後的文件拷貝到elasticsearch-2.4.6\plugins\ik目錄(沒有ik目錄請先建立)。blog
啓動ElasticSearch,IK分詞器就安裝好了。token
測試分詞地址:http://localhost:9200/_analyze?analyzer=ik&pretty=true&text=超級管理員ip
結果以下,說明IK分詞器安裝成功了
{ "tokens" : [ { "token" : "超級", "start_offset" : 0, "end_offset" : 2, "type" : "CN_WORD", "position" : 0 }, { "token" : "管理員", "start_offset" : 2, "end_offset" : 5, "type" : "CN_WORD", "position" : 1 }, { "token" : "管理", "start_offset" : 2, "end_offset" : 4, "type" : "CN_WORD", "position" : 2 }, { "token" : "員", "start_offset" : 4, "end_offset" : 5, "type" : "CN_CHAR", "position" : 3 } ] }