我正在使用elasticsearch 6.1,我正在尝试在此doc之后为我的设置添加基本同义词过滤器:https://www.elastic.co/guide/guide/en/elasticsearch/reference/Current/Analysis-synonyny-tokenfilter.html
这是我的代码:
curl -XPUT 'localhost:9200/test_index?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"search_synonyms" : {
"type": "custom",
"tokenizer" : "keyword",
"filter" : ["lowercase","synonyms"]
}
},
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms_path" : "analysis/synonyms.txt"
}
}
}
}
}
}'
我收到以下错误消息:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/analysis/synonyms.txt"
}
],
"type" : "illegal_argument_exception",
"reason" : "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/analysis/synonyms.txt",
"caused_by" : {
"type" : "no_such_file_exception",
"reason" : "/usr/share/elasticsearch/config/analysis/synonyms.txt"
}
},
"status" : 400
}
我相信这个问题来自" ...阅读synonyms_path_path:"可能只是" ...
但是,我相信我尊重文档中提到的所有功能。
此外,如果我只是尝试说:
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "analysis/synonyms.txt"
}
}
它只是不会读取文件...
我的同义词。
关于如何解决此问题的任何想法或建议?
非常感谢您的时间。
通过使用文件上的以下命令,我修复了错误消息:
sudo chmod 777 synonyms.txt
但是分析仪仍未识别文件中存在的同义词。确实是同义词。
如果我尝试:
curl -XGET 'localhost:9200/test_index/_analyze?pretty' -H 'Content-Type: application/json' -d'
{
"analyzer": "search_synonyms",
"text": "i pod"
}'
我得到:
{
"tokens" : [
{
"token" : "i pod",
"start_offset" : 0,
"end_offset" : 5,
"type" : "word",
"position" : 0
}
]
}
问题尚未完全解决,而是到达那里:)。
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "synonyms.txt"
}
}
尝试一下。它对我有用。
迟到了,但是我和docker遇到了同样的问题,就像Aurelien Quillet指出的那样。
您可能需要
之类的东西services:
elasticsearch_container:
volumes:
- ${APPLICATION}/config/packages/synonyms.txt:/usr/share/elasticsearch/config/synonyms.txt
在我的情况下, ${APPLICATION}/config/packages/synonyms.txt
是我的项目代码中的路径。
错误(/usr/share/elasticsearch/config/synonyms.txt
)中显示的路径是我的 elasticsearch 容器中的路径。