-
下載 elasticsearch-analysis-ik 安裝包
下載地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
-
安裝 IK 分詞器
-
自動安裝
cd /opt/cloudera/parcels/ELASTICSEARCH/bin ./elasticsearch-plugin install -y https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.1/elasticsearch-analysis-ik-7.0.1.zip
-
手動安裝
cd /opt/cloudera/parcels/ELASTICSEARCH/plugins wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.1/elasticsearch-analysis-ik-7.0.1.zip # 等待下載完成 mkdir analysis-ik unzip -d analysis-ik/ elasticsearch-analysis-ik-7.0.1.zip mv analysis-ik/config/ analysis-ik/analysis-ik mv analysis-ik/analysis-ik/ ../config/ rm -rf elasticsearch-analysis-ik-7.0.1.zi
-
-
ik_max_word 和 ik_smart 兩種分詞模式
-
ik_max_word 將文本做最細粒度的拆分寇漫。
例如: ik_max_word 會將 "中華人民共和國人民大會堂" 拆分為 "中華人民共和國稳吮、中華人民斧拍、中華删咱、華人、人民共和國奶赔、人民惋嚎、共和國、大會堂站刑、大會另伍、會堂"等詞語。
{"text":"中華人民共和國人民大會堂","analyzer":"ik_max_word"}
-
ik_smart 會做最粗粒度的拆分笛钝。
例如: ik_smart 會將"中華人民共和國人民大會堂"拆分為"中華人民共和國质况、人民大會堂"愕宋。
{"text":"中華人民共和國人民大會堂","analyzer":"ik_smart"}
-
-
配置自定義詞庫
-
新建自定義詞庫文件
在
${ELASTICSEARCH_HOME}/config/analysis-ik
目錄下新建custom/mydict.dic
文件(注意文件格式為 utf-8玻靡,不要選擇utf-8 BOM),可以在 my.dic 文件 中自定義詞匯中贝。 -
修改配置文件 IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 擴展配置</comment> <!--用戶可以在這里配置自己的擴展字典,多個擴展詞典以分號分隔 --> <entry key="ext_dict">custom/mydict.dic</entry> <!--用戶可以在這里配置自己的擴展停止詞字典--> <entry key="ext_stopwords"></entry> <!--用戶可以在這里配置遠程擴展字典 --> <!-- <entry key="remote_ext_dict">words_location</entry> --> <!--用戶可以在這里配置遠程擴展停止詞字典--> <!-- <entry key="remote_ext_stopwords">words_location</entry> --> </properties>
-
重啟 ES 服務(wù)后測試分詞效果
{"text": "葡萄美酒夜光杯囤捻,欲飲琵琶馬上催。醉臥沙場君莫笑邻寿,古來征戰(zhàn)幾人回蝎土?","analyzer": "ik_smart"}
自定義詞庫加入
葡萄美酒夜光杯
前:
自定義詞庫加入葡萄美酒夜光杯
后:
-
-
配置熱更新 IK 分詞
-
安裝http服務(wù), 創(chuàng)建遠程擴展字典
-
修改配置文件 IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 擴展配置</comment> <!--用戶可以在這里配置自己的擴展字典,多個擴展詞典以分號分隔 --> <entry key="ext_dict">custom/mydict.dic</entry> <!--用戶可以在這里配置自己的擴展停止詞字典--> <entry key="ext_stopwords"></entry> <!--用戶可以在這里配置遠程擴展字典 --> <entry key="remote_ext_dict">http://192.168.1.101/analysis-ik/mydict.dic</entry> <!--用戶可以在這里配置遠程擴展停止詞字典--> <!-- <entry key="remote_ext_stopwords">words_location</entry> --> </properties>
-
重啟 ES 服務(wù)后測試遠程分詞效果
[root@node01 analysis-ik]# cat mydict.dic 欲飲琵琶馬上催 醉臥沙場君莫笑 古來征戰(zhàn)幾人回
-