Windows10安裝Elasticsearch IK分詞插件


安裝插件

cmd切換到Elasticsearch安裝目錄下

C:\Users\Administrator>D:

D:\>cd D:\Program Files\Elastic\ElasticSearch\6.8.4\bin

安裝的插件需要跟Elasticsearch的版本匹配,也就是說我要裝的是6.8.4版本的ik分詞插件。
訪問下載頁面:Releases · medcl/elasticsearch-analysis-ik
找到6.8.4的下載鏈接,執行以下命令

elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.4/elasticsearch-analysis-ik-6.8.4.zip

執行結果示例:

D:\Program Files\Elastic\Elasticsearch\6.8.4\bin>elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.4/elasticsearch-analysis-ik-6.8.4.zip
-> Downloading https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.4/elasticsearch-analysis-ik-6.8.4.zip
[=================================================] 100%??
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed analysis-ik

不知道如何驗證是否安裝成功,可以先使用幫助命令elasticsearch-plugin -h查看可用的命令

D:\Program Files\Elastic\Elasticsearch\6.8.4\bin>elasticsearch-plugin -h
A tool for managing installed elasticsearch plugins

Commands
--------
list - Lists installed elasticsearch plugins
install - Install a plugin
remove - removes a plugin from Elasticsearch

Non-option arguments:
command

Option         Description
------         -----------
-h, --help     show help
-s, --silent   show minimal output
-v, --verbose  show verbose output

由上文得出,可以使用elasticsearch-plugin list查看已安裝得插件。

D:\Program Files\Elastic\Elasticsearch\6.8.4\bin>elasticsearch-plugin list
analysis-icu
analysis-ik

analysis-ik ik插件已成功安裝。

測試ik分詞

測試ik分詞可以由多種方式

chrome瀏覽器插件elasticsearch-head

下載地址:ElasticSearch Head - Chrome 網上應用店
如果不能咳咳,可以訪問 mobz/elasticsearch-head: A web front end for an elastic search cluster按照指示自行安裝。
測試結果類似以下界面

kibana的Dev Tools

Postman

自定義詞典

詞典配置IKAnalyzer.cfg.xml,我的配置路徑D:\ProgramData\Elastic\Elasticsearch\config\analysis-ik\

<?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"></entry>
	 <!--用戶可以在這里配置自己的擴展停止詞字典-->
	<entry key="ext_stopwords"></entry>
	<!--用戶可以在這里配置遠程擴展字典 -->
	<!-- <entry key="remote_ext_dict">words_location</entry> -->
	<!--用戶可以在這里配置遠程擴展停止詞字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

初始配置如上所示,配置文件當前目錄下,新建文本文件temp.dic
輸入以下內容,保存,不同詞之間使用換行

如家
周樹人

修改配置如下,保存,然后重啟Elasticsearch服務,即可使用拓展詞典。

<?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">temp.dic;</entry>
	 <!--用戶可以在這里配置自己的擴展停止詞字典-->
	<entry key="ext_stopwords"></entry>
	<!--用戶可以在這里配置遠程擴展字典 -->
	<!-- <entry key="remote_ext_dict">words_location</entry> -->
	<!--用戶可以在這里配置遠程擴展停止詞字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

多個詞典,以英文分號分隔。


免責聲明!

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



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