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>

多个词典,以英文分号分隔。

猜你喜欢

转载自www.cnblogs.com/AlienXu/p/elasticsearch-analysis-ik.html