GitHub IK插件地址
https://github.com/medcl/elasticsearch-analysis-ik
需要注意IK插件的版本,要和ElasticSearch對應(yīng),否則出錯(而且應(yīng)該按照第二種命令的方式進(jìn)行下載,簡單不易錯,開始按照第一種出現(xiàn)了找不到文件的錯誤)
1.安裝方式(我用第一種錯誤了,第二種直接就好使,但是主要版本對應(yīng)關(guān)系)
optional 1 - download pre-build package from here: https://github.com/medcl/elasticsearch-analysis-ik/releases unzip plugin to folder your-es-root/plugins/
optional 2 - use elasticsearch-plugin to install ( version > v5.5.1 ): ./bin/elasticsearch-plugin install [https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.1/elasticsearch-analysis-ik-5.6.1.zip](https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.1/elasticsearch-analysis-ik-5.6.1.zip)
| IK version | ES version |
|---|---|
| 5.6.1 | 5.6.1 |
| 5.5.3 | 5.5.3 |
2.安裝完成之后可以測試效果對比
1.測試內(nèi)置的標(biāo)準(zhǔn)分析器效果standard
curl -XPOST http://localhost:9200/_analyze?pretty -d '{ "analyzer": "standard", "text": "庖丁解牛成語中文english test" }'
2.測試剛剛安裝好的ik分詞分析器插件的效果
curl -XPOST http://localhost:9200/_analyze?pretty -d '{ "analyzer": "ik_max_word", "text": "庖丁解牛成語中文english test" }'
3.GitHub上復(fù)制的原話(就用ik_max_word靠譜)
移除名為 ik 的analyzer和tokenizer,請分別使用 ik_smart 和 ik_max_word
ik_max_word 和 ik_smart 什么區(qū)別?
ik_max_word: 會將文本做最細(xì)粒度的拆分,比如會將“中華人民共和國國歌”拆分為“中華人民共和國,中華人民,中華,華人,人民共和國,人民,人,民,共和國,共和,和,國國,國歌”,會窮盡各種可能的組合;
ik_smart: 會做最粗粒度的拆分,比如會將“中華人民共和國國歌”拆分為“中華人民共和國,國歌”。
4.ElasticSearch Reference的地址,解析Analyzer
https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer-anatomy.html
Anlyzer由character filter+tokenizer+token filter組成,添加的這個ik實際上主要是tonkenizer分詞器的效果,之后要改可以和其他filter組合 IK的Git上的一句話:Analyzer: ik_smart , ik_max_word , Tokenizer: ik_smart , ik_max_word 組合示例(這個就是看一下,不能復(fù)制直接用) POST _analyze { "tokenizer": "standard", "filter": [ "lowercase", "asciifolding" ], "text": "Is this déja vu?" }
3.IK熱更新IK Analysis for Elasticsearch
https://github.com/medcl/elasticsearch-analysis-ik
修改 elasticsearch-root目錄/config/analysis-ik/IKAnalyzer.cfg.xml
<!-用戶可以在這里配置遠(yuǎn)程擴(kuò)展字典 -->
<entry key="remote_ext_dict">http://localhost:8080/elasticsearch/ik/remote_my_dict.txt</entry>
其實配置好那個url就可以,隨便用什么可以被訪問的http服務(wù)器就行(我在linux弄的tomcat)
配置好之后在remote_my_dict.txt中隨時添加詞就可以,不用重啟elasticsearch的服務(wù)(但是加完詞,測試查詢不會立馬生效,得過個10多秒,不知道具體怎么回事.估計是用定時器去特定時間發(fā)送那個鏈接的請求吧) `