elasticsearch 6.1 error:读取synonyms_path_path时发生IOException

时间:2017-12-27 10:50:42

标签: elasticsearch

我正在使用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
}

我认为这个问题来自于“...... reading synonyms_path_path:”,这应该只是“......读同义词路径:”。

但是,我相信我尊重文档中提到的所有功能。

此外,如果我试着放下:

"filter" : {
     "synonyms" : {
          "type" : "synonym",
          "synonyms" : "analysis/synonyms.txt"
      }
 }

它只是不读取文件...

我的synonyms.txt与solr格式文档中显示的文件完全相同。

有关如何解决此问题的任何想法或建议?

非常感谢你的时间。

3 个答案:

答案 0 :(得分:0)

通过在文件中使用以下命令,我修复了错误消息:

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
    }
  ]
}

问题尚未完全解决,但到了那里:)。

答案 1 :(得分:0)

"filter" : {
     "synonyms" : {
          "type" : "synonym",
          "synonyms" : "synonyms.txt"
      }
 }

试试这个。它对我有用。

答案 2 :(得分:0)

有点晚了,但正如 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 容器中的路径。

相关问题