我正在使用elasticsearch 6.1,并且我正在尝试添加一个基本的同义词过滤器到我的设置中,遵循这个文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-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:“,应该只是"...阅读synonyms_path:”。
然而,我相信我尊重文档中提到的所有功能。
此外,如果我试着把:
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "analysis/synonyms.txt"
}
}它只是不读取文件然后..。
我的synonyms.txt与文档中显示的solr格式的文件完全相同。
对如何解决这个问题有什么想法或建议吗?
非常感谢您的宝贵时间。
发布于 2017-12-28 16:41:12
通过在文件上使用以下命令,我修复了错误消息:
sudo chmod 777 synonyms.txt但是分析器仍然无法识别文件中存在的同义词。确实synonyms.txt包含: i- pod,i pod => ipod
如果我试一试:
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
}
]
}问题尚未完全解决,但正在实现:)。
发布于 2021-01-05 14:05:10
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "synonyms.txt"
}
}尝尝这个。这对我很管用。
发布于 2021-01-27 18:43:29
有点晚了,但正如Aurelien Quillet指出的那样,我对docker也有同样的问题。
你可能需要像这样的东西
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容器中的路径。
https://stackoverflow.com/questions/47990855
复制相似问题