elasticsearch ik分词 远程自动更新自定义词典 需要满足两个条件:
1.GET请求返回词典列表。
2. nginx 服务器 HEAD请求响应头返回Last-Modified和(或)ETag。
根据这两个条件,可以分为直接访问资源文件和访问接口两种方式。
文件
以文件方式更新词典,将词放在一个utf8编码的文件里,将文件放在nginx或其他server下,当文件修改时http server会在客户端请求文件时自动返回响应的Last-Modified和ETag。在analysis-ik检测到词典更新时会自动更新。
以nginx为例,假设词典文件名为mydic.dic。前提条件如nginx配置、IKAnalyzer.cfg.xml配置、重启等步骤此处省略,当词典为空文件时。
配置
vim /usr/local/elasticsearch/plugins/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"></entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<entry key="remote_ext_dict">http://172.168.10.48/dict/brand.dic;http://172.168.10.48/dict/attr.dic;http://172.168.10.48/dict/category.dic</entry>
<!--用户可以在这里配置远程扩展停止词字典-->
<entry key="remote_ext_stopwords">http://172.168.10.48/dict/stop.dic</entry>
</properties>
日志
[root@k8s-node3 log]# tail -f beta_elasticsearch.log
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 比较仪台架
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 其它工业用水处理设备
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 家用垃圾桶
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 6.3MM系列十字旋具头套筒
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 除污器
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 双色橡塑柄加力一字螺丝批
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] SDS信息栏
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 防盗锁芯
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 分析天平
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 真空计量
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 光柄扎线钳
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 双金属复合管帽
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 恒温槽
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 鸡尾锯
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 喉箍
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 热风焊枪
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 管端突缘
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 动力工具及耗材
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 橡胶水带
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 密封圈、条
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 普通压力表配件
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 135°塑料弯头
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 台垫
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 井架逃生装置
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 精密恒温水槽
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 塑料量筒
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 12.5MM系列英制十二角套筒
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 钢制门锁体
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 防尘连接管
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 结构粘接胶
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 浇铸用耐火砖
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 沥青烘干清漆
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 防腐活接头
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 加样槽
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 口罩
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 绝缘公制六角套筒
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 桩工机械
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 导热油锅炉
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] 摇式给料机
[2021-02-05T11:16:03,862][INFO ][o.w.a.d.Dictionary ] [node-48] [Dict Loading] http://172.168.10.48/dict/stop.dic
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] [
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] ]
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] {
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] }
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] &
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] *
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] /
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] \
[2021-02-05T11:16:03,864][INFO ][o.w.a.d.Dictionary ] [node-48] reload ik dict finished.