我正試圖學習如何正確添加「同義詞功能」到我現有的ElasticSearch設置。以下是我對此過程的理解。如果您能指出我的任何誤解,我會很感激的 - 我對elasticsearch很陌生。基本ElasticSearch + WordNet同義詞設置與預先存在的索引
從this page我已經學會了,我需要一個路徑我的同義詞文件中添加的代名詞分析儀的代名詞過濾器,以我的索引配置,使它看起來像這樣:
{
"index" : {
"analysis" : {
"analyzer" : {
"synonym" : {
"tokenizer" : "whitespace",
"filter" : ["synonym"]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"format" : "wordnet",
"synonyms_path" : "analysis/wordnet_synonyms.txt"
}
}
}
}
}
從this page我已經學會了如何添加分析儀:
curl -XPOST 'localhost:9200/myindex/_close'
curl -XPUT 'localhost:9200/myindex/_settings' -d '{
"analysis" : {
"analyzer":{
"synonym":{
"tokenizer":"whitespace",
"filter" : ["synonym"]
}
}
}
}'
curl -XPOST 'localhost:9200/myindex/_open'
但我不知道如何添加過濾器。難道是像這樣簡單?:
curl -XPOST 'localhost:9200/myindex/_close'
curl -XPUT 'localhost:9200/myindex/_settings' -d '{
"analysis" : {
"filter":{
"synonym":{
"type" : "synonym",
"format" : "wordnet",
"synonyms_path" : "analysis/wordnet_synonyms.txt",
"ignore_case" : true
}
}
}
}'
curl -XPOST 'localhost:9200/myindex/_open'
我也不知道哪裏analysis/wordnet_synonyms.txt
是相對。在this page它說「相對於config
位置」。 config
位置在哪裏?在etc/elasticsearch
某處(在Ubuntu上)?謝謝!
編輯:This answer給出了這樣的解決方案:
curl -XPOST 'localhost:9200/myindex/_close'
curl -XPUT 'localhost:9200/myindex/_settings' -d '{
"analysis" : {
"analyzer" : {
"synonym" : {
"tokenizer" : "whitespace",
"filter" : ["synonym"]
}
},
"filter":{
"synonym":{
"type" : "synonym",
"format" : "wordnet",
"synonyms_path" : "analysis/wordnet_synonyms.txt",
"ignore_case" : true
}
}'
curl -XPOST 'localhost:9200/myindex/_open'
這可能嗎?一位評論者說,當更改分析儀設置時,需要重新創建索引 - 這是真的嗎?而且我還不確定在哪裏放置「wordnet_synonyms.txt」。
謝謝,這工作,但我正在尋找一種方法來做到預先存在的索引,但如果沒有辦法,我會接受你的答案爲是。 – JoeRocc
唯一的問題是您的字段已存在。您肯定可以修改設置併爲您的新分析儀添加一個新的區域,但不能將分析儀添加到已經存在的區域。 – Val
感謝您的澄清! – JoeRocc