美文网首页
安装 elasticsearch-analysis-ik-5.1

安装 elasticsearch-analysis-ik-5.1

作者: mugtmag | 来源:发表于2018-03-07 16:46 被阅读154次

elasticsearch-analysis-ik 是一个比较常用的中文分词器

cjk也支持中文,相当于是bigram, elasticsearch对中文默认分析器是unigram 的分析器(即默认的 Standard Analyzer),即每个字是一个词,效果不太好
比较常用的两个效果较好的中文分词器是ik和jieba,但是jieba只支持<=2.35版的elasticsearch

安装ik:
  • 下载 elasticsearch-analysis-ik-5.1.1.zip (注意:和elasticsearch版本对应),直接下载其release的版本(第一个zip文件,避免maven打包)
    https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v5.1.1
  • 在/Users/duhuifang/Downloads/elasticsearch-5.1.1/plugins下建立ik目录
    mkdir ik
  • 移动 elasticsearch-analysis-ik-5.1.1.zip至elasticsearch的plugins文件夹的ik文件夹下:
cp Downloads/ elasticsearch-analysis-ik-5.1.1.zip /Users/duhuifang/Downloads/elasticsearch-5.1.1/plugins/ik
  • 解压文件
    unzip elasticsearch-analysis-ik-5.1.1.zip
  • 启动elasticsearch,即可看到加载了analysis-ik插件
可以自定义分词词表
  • 在/Users/duhuifang/Downloads/elasticsearch-5.1.1/plugins/ik/config/custom文件夹下可放进自己的词典,然后在/Users/duhuifang/Downloads/elasticsearch-5.1.1/plugins/ik/config/IKAnalyzer.cfg.xml配置文件中写入自定义词库的路径即可,如图:

配置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>
    <!--用户可以在这里配置自己的扩展字典,我增加的是memect.dic -->
    <entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic;custom/memect.dic;</entry>
     <!--用户可以在这里配置自己的扩展停止词字典-->
    <entry key="ext_stopwords">custom/ext_stopword.dic</entry>
    <!--用户可以在这里配置远程扩展字典 -->
    <!-- <entry key="remote_ext_dict">words_location</entry> -->
    <!--用户可以在这里配置远程扩展停止词字典-->
    <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

相关文章

网友评论

      本文标题:安装 elasticsearch-analysis-ik-5.1

      本文链接:https://www.haomeiwen.com/subject/iftfsxtx.html