1. 下载地址

https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.8.0

2. 安装

  • 解压
  • 将整个文件夹放到 /opt/module/es-cluster/plugin/

image.png

  • 分发,重启ES集群
    1. xsync.sh plugins/

    3. 测试

    3.1 使用标准分词器分词

    ```http GET /_analyze { “analyzer”: “standard”, “text”: “中国人” }

“analyzer”: “standard”:使用标准分词器分词

“text”: “中国人”:指定测试文本

  1. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/668367/1628433259039-00eb0e5b-326a-4f49-bdc1-aa34332ca0b6.png#crop=0&crop=0&crop=1&crop=1&height=332&id=z2iPo&margin=%5Bobject%20Object%5D&name=image.png&originHeight=664&originWidth=491&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34599&status=done&style=none&title=&width=245.5)
  2. <a name="B7Rtb"></a>
  3. ## 3.2 使用IK分词器分词
  4. <a name="fc06Z"></a>
  5. ### 3.2.1 使用ik_max_word
  6. > 会将文本做**最细粒度**的拆分
  7. ```http
  8. GET /_analyze
  9. {
  10. "analyzer": "ik_max_word",
  11. "text": "中国人"
  12. }
  13. # "analyzer": "ik_max_word":是指定使用哪个分词器,ik_max_word会将文本做最细粒度的拆分
  14. # "text": "中国人":指定测试文本

image.png

3.2.2 使用ik_smart

会将文本做最粗粒度的拆分

  1. GET /_analyze
  2. {
  3. "analyzer": "ik_smart",
  4. "text": "中国人"
  5. }
  6. # "analyzer": "ik_smart":是指定使用哪个分词器,ik_smart会将文本做最粗粒度的拆分
  7. # "text": "中国人":指定测试文本

image.png

4. 自定义扩展词汇、停止词汇

4.1 扩展词汇

  1. GET /_analyze
  2. {
  3. "analyzer": "ik_smart",
  4. "text": "艾欧尼亚"
  5. }
  • 未定义时:

image.png

  • 定义时

    • /opt/module/es-cluster/plugins/elasticsearch-analysis-ik-7.8.0/config 下创建 custom.dic 文件

      1. touch custom.dic
    • custom.dic 中增加扩展词汇

      1. 艾欧尼亚
    • IKAnalyzer.cfg.xml中增加自定义的扩展词典

      1. <?xml version="1.0" encoding="UTF-8"?>
      2. <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
      3. <properties>
      4. <comment>IK Analyzer 扩展配置</comment>
      5. <!--用户可以在这里配置自己的扩展字典 -->
      6. <entry key="ext_dict">custom.dic</entry>
      7. <!--用户可以在这里配置自己的扩展停止词字典-->
      8. <entry key="ext_stopwords"></entry>
      9. <!--用户可以在这里配置远程扩展字典 -->
      10. <!-- <entry key="remote_ext_dict">words_location</entry> -->
      11. <!--用户可以在这里配置远程扩展停止词字典-->
      12. <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
      13. </properties>
    • 分发

      1. xsync.sh plugins/
    • 重启es集群,查看效果

image.png

4.2 停止词汇

基本同4.1 扩展词汇