elasticsearch(4)安装hanlp中文分词插件

为了做基于分词和基于模板的智能客服系统,引入了hanlp 分词器,直接整: hanlp 分词是针对中文分词开发的分词库。

elasticsearch集成hanlp 不能直接去下载hanlp,需要集成elasticsearch-hanlp插件。

在github,中有很多 es-hanlp的插件,多数是坑。


下载 https://github.com/hualongdata/hanlp-ext/tree/master/es-plugin#elasticsearch-hanlp


下载源码:然后根据自己ES版本和hanlp版本进行修改,然后编译打包。可以根据自己的需要对分词器进行代码修改。

elasticsearch-hanlp

当前支持分词类型:

  • hanlp / hanlp-standard: 标准分词
  • hanlp-index: 索引分词

编译、安装、测试

文件路径按着自己的安装路径设置

  1. 编译、打包插件
gradle -p es-plugin jar buildPluginZip
  1. 使用命令安装插件
ES_HOME/bin/elasticsearch-plugin install file:///home/hldev/hldata/data/hanlp-ext/es-plugin/build/distributions/elasticsearch-hanlp-5.4.3.zip
  1. 修改 ES_HOME/config 目录下的 jvm.options 文件添加一行(读取hanlp.properties配置文件需要)
-Djava.security.policy=file:///你的ES目录/plugins/elasticsearch-hanlp/plugin-security.policy
  1. 最后修改ES/bin/elasticsearch.in.sh文件将 ES_CLASSPATH修改为
ES_CLASSPATH="$ES_HOME/lib/elasticsearch-5.4.3.jar:$ES_HOME/lib/*:$ES_HOME/plugins/elasticsearch-hanlp/"

最后运行elasticsearch即可

测试方法:

分别使用以下两种方式测试分词效果:

GET /_analyze?pretty
{
  "analyzer" : "hanlp",
  "text" : ["重庆华龙网海数科技有限公司"]
}

你可能感兴趣的:(elasticsearch)