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