在 Elasticsearch 中加载自定义同义词文件时出错
Posted
技术标签:
【中文标题】在 Elasticsearch 中加载自定义同义词文件时出错【英文标题】:Error loading custom synonym file in Elasticsearch 【发布时间】:2013-02-11 19:07:16 【问题描述】:我在 EC2 单服务器设置上使用 Rails、Tire 和 Elasticsearch,没有分片或复制(这是 Jenkins CI 服务器)。使用这样的自定义初始化程序:
analysis:
filter:
name_synonyms:
type: synonym
synonyms_path: <%= Rails.root.join("config", "synonyms", "name_synonyms.txt") %>
这个文件通过 Erubis 运行,同义词路径被转换成这样的东西:
/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt
当我列出服务器中的文件时,我看到以下内容:
root@ip-XX-XXX-XX-XXX:~/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms# ls -la
total 20
drwxr-xr-x 2 root root 4096 Feb 11 18:25 .
drwxr-xr-x 7 root root 4096 Feb 11 18:25 ..
-rw-r--r-- 1 root root 3117 Feb 11 18:25 location_synonyms.txt
-rw-r--r-- 1 root root 3999 Feb 11 18:25 name_synonyms.txt
-rw-r--r-- 1 root root 2144 Feb 11 18:25 term_synonyms.txt
这正是我所期待的,但是我在运行 rake spec
时看到以下错误
500 : "error":"IndexCreationException[[test_facilities] failed to create index]; nested: FailedToResolveConfigException[Failed to resolve config path [/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], tried file path [/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], path file [/etc/elasticsearch/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt], and classpath]; ","status":500
在我看来,虽然路径正确,但 Elasticsearch 无法加载文件,可能是加载顺序问题,我真的不太确定。
【问题讨论】:
您的集群中有多少个节点?该文件是否存在于所有节点上? 这是一个单一的 EC2 实例。它是运行 Jenkins 的 CI 实例。所以它在技术上应该只知道自己。 @imotov 原来这与文件和父文件夹的读取/执行权限有关。 刚刚遇到同样的问题, chmod o+x $HOME 成功了。主文件夹的默认模式是 0700,这会阻止 elasticsearch 用户进入主文件夹以读取配置文件。 【参考方案1】:您应该查看 elasticsearch 日志文件。在我的情况下/var/log/elasticsearch/elasticsearch.log
就我而言,我有这个:
[2016-02-26 10:28:26,321][WARN ][cluster.action.shard ] [Batragon] [myindex-1][2] received shard failed for [myindex-1][2], node[mynode], [P], v[1223], s[INITIALIZING], a[id=myid], unassigned_info[[reason=ALLOCATION_FAILED], at[2016-02-26T09:28:26.168Z], details[failed to create index, failure IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")]; ]], indexUUID [haZBzLsuSmmxteIq-1K0vw], message [failed to create index], failure [IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")]; ]
[myindex-1] IndexCreationException[failed to create index]; nested: AccessControlException[access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")];
at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:360)
at org.elasticsearch.indices.cluster.IndicesClusterStateService.applyNewIndices(IndicesClusterStateService.java:307)
at org.elasticsearch.indices.cluster.IndicesClusterStateService.clusterChanged(IndicesClusterStateService.java:176)
at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:494)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "/home/myuser/elasticsearch/my_synonyms.txt" "read")
...
我通过授予 java.policy 文件的读取权限(在我的情况下为 /usr/lib/jvm/java-7-oracle/jre/lib/security/java.policy
)解决了这个问题:
grant
permission java.io.FilePermission "/home/myuser/elasticsearch/my_synonyms.txt", "read";
;
并重新启动 elasticsearch 服务。
您可以以更通用的方式在目录级别授予目录中任何文件的权限,例如:
grant
permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/-", "read";
permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/", "read";
;
文件的整个路径的执行权限也是必要的。就我而言:current
和 current/config
【讨论】:
【参考方案2】:文件的路径包含在 ES 索引映射中。在创建索引时,文件本身应该存在于 ES 服务器上,但您已经定义了该文件相对于 Rails 应用程序的路径。
【讨论】:
以上是关于在 Elasticsearch 中加载自定义同义词文件时出错的主要内容,如果未能解决你的问题,请参考以下文章