elasticsearch中文分詞器(ik)配置


elasticsearch默認的分詞:http://localhost:9200/userinfo/_analyze?analyzer=standard&pretty=true&text=我是中國人 (或者不寫analyzer=standard)

分詞之后是:“我”“是”“中”“國”“人“,會將每一個詞都拆開。
使用ik對中文分詞 http://localhost:9200/userinfo/_analyze?analyzer=ik&pretty=true&text=我是中國人
分詞之后是:“我”“中國人”“中國”“國人”

1.在github上下載ik分詞器的源碼
下載地址:https://github.com/medcl/elasticsearch-analysis-ik
下載時候注意對應的es的版本

選擇源碼版本方式:


由於是maven工程,下載完成后將工程導入到eclipse中編譯打包一下

2.將編譯打包后的\target\releases\elasticsearch-analysis-ik-1.10.0.zip 解壓后所有文件拷貝到 elasticsearch目錄下的plugins\analysis-ik目錄下

3.在elasticsearch的config/elasticsearch.yml 添加配置
index.analysis.analyzer.ik.type : "ik"
或者
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true


ik、ik_max_word、ik_smart
ik等同於ik_max_word,會將文本做最細粒度的拆分。例如“我”“中國人”“中國”,“國人”
而 ik_smart 會做最粗粒度的拆分。拆分結果則是“我”“中國人”。

 

4. elasticsearch 5.0及以上版本配置變動
1.移除名為 ik 的analyzer和tokenizer,請分別使用 ik_smart 和 ik_max_word
2.不需要在config/elasticsearch.yml 配置

 

參考網站:http://blog.csdn.net/liuzhenfeng/article/details/39404435
http://jack-boy.iteye.com/blog/2171853

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM