ES学习(五)同义词分词器dynamic synonym for ElasticSearch

dynamic synonym for ElasticSearch

elasticsearch动态同义词插件是添加一个同义词过滤器在给定间隔(默认60秒)来重新加载同义词文件(本地文件或远程文件)。


一.下载

根据自身的elasticsearch版本从官网中找到相应版本的源码:
https://github.com/bells/elasticsearch-analysis-dynamic-synonym/tree/master
这里版本使用2.3.0

二.安装

1.mvn package
2.copy and unzip target/releases/elasticsearch-analysis-dynamic-synonym-{version}.zip to your-es-root/plugins/dynamic-synonym
3.修改plugin-descriptor.properties
这里写图片描述

三.重启elasticsearch

1.ps -ef | grep elasticsearch
2.kill -9 xxx
3.bin/elasticsearch -d

四.注意事项

在启动过程中会报和ik或者pinyin分词器jar包冲突的错误,只要删除掉dynamic synonym里的jar即可

五.建立索引

crul XPOST 'http://localhost:19200/dstest/'
'{
"settings": {
"index": {
"analysis": {
"analyzer": {
"my_synonym": {
"tokenizer": "whitespace",
"filter": [
"remote_synonym"
]
}
},
"filter": {
"remote_synonym": {
"type": "dynamic_synonym",
"synonyms_path": "http://localhost:1111/dics/synonym.txt",
"interval": 30
}
}
}
}
},
"mapping": {
"product": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "my_synonym"
}
}
}
}
} '

测试

txt测试数据:刘海霞,李帅,土豆
http://localhost:19200/dstest/_analyze?text=刘海霞&analyzer=my_synonym
结果:
{"tokens":[{"token":"刘海霞","start_offset":0,"end_offset":3,"type":"word","position":0},{"token":"李帅","start_offset":0,"end_offset":3,"type":"SYNONYM","position":0},{"token":"土豆","start_offset":0,"end_offset":3,"type":"SYNONYM","position":0}]}
成功!


参考:https://github.com/bells/elasticsearch-analysis-dynamic-synonym/tree/master

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章