ElasticSearch 6.x 配置IK 扩展字典

一、安装IK https://github.com/medcl/elasticsearch-analysis-ik

(以下为官方提供的安装方法)

Install

1.download or compile

  • optional 1 - download pre-build package from here: https://github.com/medcl/elasticsearch-analysis-ik/releases

    unzip plugin to folder your-es-root/plugins/

  • optional 2 - use elasticsearch-plugin to install ( supported from version v5.5.1 ):

    ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.3/elasticsearch-analysis-ik-6.2.3.zip
    
    

    NOTE: replace 6.2.3 to your own elasticsearch version

2.restart elasticsearch

以上是官方给出的安装示例,需要下载和 ES 版本的对应 IK 版本(官方 github 中有),windows 开发环境下下载IK 解压到 plugin 目录下即可。

二、测试 IK 分词器

#请求
POST http://39.107.70.75:9200/_analyze
{
  "analyzer": "ik_smart",
  "text":"俄罗斯世界杯即将开幕"
}
#结果
{
"tokens":[
{"token": "俄罗斯", "start_offset": 0, "end_offset": 3, "type": "CN_WORD",…},
{"token": "世界杯", "start_offset": 3, "end_offset": 6, "type": "CN_WORD",…},
{"token": "即将", "start_offset": 6, "end_offset": 8, "type": "CN_WORD",…},
{"token": "开幕", "start_offset": 8, "end_offset": 10, "type": "CN_WORD",…}
]
}

此时 IK 分词已经生效

补充:ik_max_word 和 ik_smart 什么区别?

  • IK 5.0 以后,移除名为 ik 的analyzer和tokenizer 只能使用 ik_smart 和 ik_max_word
  • ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;
  • ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。

三、扩展字典

1)修改 /elasticsearch-6.2.3/plugins/analysis-ik/config/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>
    <!--用户可以在这里配置自己的扩展字典 -->
    <entry key="ext_dict">./extra_new_word.dic</entry>
     <!--用户可以在这里配置自己的扩展停止词字典-->
    <entry key="ext_stopwords"></entry>
    <!--用户可以在这里配置远程扩展字典 -->
    <!-- <entry key="remote_ext_dict">words_location</entry> -->
    <!--用户可以在这里配置远程扩展停止词字典-->
    <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

2)新建 extra_new_word.dic (UTF-8编码)

继电保护通道
分相电流差动
历渤
鹤历
鹤辽
程王
蒲抚

3)重启 es
4)新增扩展词后,让历史数据生效

POST
http://39.107.70.75:9200/station_index,cable_index,transmission_index,business_index/_update_by_query?c

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值