在 Elasticsearch 中加载自定义同义词文件时出错

bru*_*upm 4 java ruby-on-rails elasticsearch tire

我在 EC2 单服务器设置上使用 Rails、Tire 和 Elasticsearch,没有分片或复制(这是 Jenkins CI 服务器)。使用自定义初始值设定项:

analysis:
  filter:        
    name_synonyms:
      type: synonym
      synonyms_path: <%= Rails.root.join("config", "synonyms", "name_synonyms.txt") %>
Run Code Online (Sandbox Code Playgroud)

该文件通过 Erubis 运行,同义词路径转换为如下所示:

/root/workspace/project-project-0f317744a1870b4baf61bbaeb390ebe1/config/synonyms/term_synonyms.txt
Run Code Online (Sandbox Code Playgroud)

当我列出服务器中的文件时,我看到以下内容:

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
Run Code Online (Sandbox Code Playgroud)

这正是我所期待的,但是我在运行时看到以下错误 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}
Run Code Online (Sandbox Code Playgroud)

在我看来,虽然路径正确,但 Elasticsearch 无法加载文件,这可能是加载顺序问题,我真的不太确定。

jog*_*aco 5

您应该查看 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")
  ...
Run Code Online (Sandbox Code Playgroud)

我通过授予 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";
};
Run Code Online (Sandbox Code Playgroud)

并重新启动elasticsearch服务。

您可以以更通用的方式在目录级别授予权限给目录中的任何文件,例如:

    grant {
    permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/-", "read";
    permission java.io.FilePermission "/home/myuser/current/config/elasticsearch/", "read";
};
Run Code Online (Sandbox Code Playgroud)

对文件的整个路径的执行权限也是必要的。就我而言:currentcurrent/config