infinilabs / analysis-ik

🚌 The IK Analysis plugin integrates Lucene IK analyzer into Elasticsearch and OpenSearch, support customized dictionary.
Apache License 2.0
16.63k stars 3.28k forks source link

IK 1.10.6 安装后无法找到 IKAnalyzer.cfg.xml 以及 main.dic #467

Open twang2218 opened 7 years ago

twang2218 commented 7 years ago

我使用下面的 Dockerfile 来构建并重现这个问题:

FROM elasticsearch:2.4

ENV TZ Asia/Shanghai
ENV LANG C.UTF-8

ENV IK_VERSION 1.10.6
RUN plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v$IK_VERSION/elasticsearch-analysis-ik-$IK_VERSION.zip

其中使用 plugin install 来安装的插件。构建一切正常,但是启动 elastic search 后,会立即报错退出。其返回的错误信息如下:

elastic_1   | [2017-11-21 14:11:00,296][WARN ][bootstrap                ] unable to install syscall filter: seccomp unavailable: your kernel is buggy and you should upgrade
elastic_1   | [2017-11-21 14:11:00,474][INFO ][node                     ] [Blue Marvel] version[2.4.6], pid[1], build[5376dca/2017-07-18T12:17:44Z]
elastic_1   | [2017-11-21 14:11:00,474][INFO ][node                     ] [Blue Marvel] initializing ...
elastic_1   | [2017-11-21 14:11:01,189][INFO ][plugins                  ] [Blue Marvel] modules [reindex, lang-expression, lang-groovy], plugins [analysis-ik], sites []
elastic_1   | [2017-11-21 14:11:01,261][INFO ][env                      ] [Blue Marvel] using [1] data paths, mounts [[/usr/share/elasticsearch/data (/dev/sda5)]], net usable_space [1.6tb], net total_space [1.7tb], spins? [possibly], types [ext4]
elastic_1   | [2017-11-21 14:11:01,262][INFO ][env                      ] [Blue Marvel] heap size [989.8mb], compressed ordinary object pointers [true]
elastic_1   | [2017-11-21 14:11:02,814][INFO ][ik-analyzer              ] try load config from /usr/share/elasticsearch/config/analysis-ik/IKAnalyzer.cfg.xml
elastic_1   | [2017-11-21 14:11:02,815][INFO ][ik-analyzer              ] try load config from /usr/share/elasticsearch/plugins/analysis-ik/config/IKAnalyzer.cfg.xml
elastic_1   | [2017-11-21 14:11:02,816][ERROR][ik-analyzer              ] ik-analyzer
elastic_1   | java.io.FileNotFoundException: /usr/share/elasticsearch/config/analysis-ik/IKAnalyzer.cfg.xml (No such file or directory)
elastic_1   |   at java.io.FileInputStream.open0(Native Method)
elastic_1   |   at java.io.FileInputStream.open(FileInputStream.java:195)
elastic_1   |   at java.io.FileInputStream.<init>(FileInputStream.java:138)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.<init>(Dictionary.java:108)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.initial(Dictionary.java:148)
elastic_1   |   at org.wltea.analyzer.cfg.Configuration.<init>(Configuration.java:47)
elastic_1   |   at org.elasticsearch.indices.analysis.IKIndicesAnalysis.<init>(IKIndicesAnalysis.java:30)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
elastic_1   |   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
elastic_1   |   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
elastic_1   |   at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:50)
elastic_1   |   at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86)
elastic_1   |   at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104)
elastic_1   |   at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:47)
elastic_1   |   at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:886)
elastic_1   |   at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:43)
elastic_1   |   at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:59)
elastic_1   |   at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:201)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193)
elastic_1   |   at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:879)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:193)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:175)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110)
elastic_1   |   at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
elastic_1   |   at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
elastic_1   |   at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:46)
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:213)
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:140)
elastic_1   |   at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
elastic_1   |   at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:45)
elastic_1   | [2017-11-21 14:11:02,820][ERROR][ik-analyzer              ] /usr/share/elasticsearch/plugins/analysis-ik/config/main.dic (No such file or directory)
elastic_1   | java.io.FileNotFoundException: /usr/share/elasticsearch/plugins/analysis-ik/config/main.dic (No such file or directory)
elastic_1   |   at java.io.FileInputStream.open0(Native Method)
elastic_1   |   at java.io.FileInputStream.open(FileInputStream.java:195)
elastic_1   |   at java.io.FileInputStream.<init>(FileInputStream.java:138)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.loadMainDict(Dictionary.java:347)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.initial(Dictionary.java:149)
elastic_1   |   at org.wltea.analyzer.cfg.Configuration.<init>(Configuration.java:47)
elastic_1   |   at org.elasticsearch.indices.analysis.IKIndicesAnalysis.<init>(IKIndicesAnalysis.java:30)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
elastic_1   |   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
elastic_1   |   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
elastic_1   |   at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:50)
elastic_1   |   at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86)
elastic_1   |   at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104)
elastic_1   |   at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:47)
elastic_1   |   at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:886)
elastic_1   |   at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:43)
elastic_1   |   at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:59)
elastic_1   |   at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:201)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193)
elastic_1   |   at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:879)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:193)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:175)
elastic_1   |   at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110)
elastic_1   |   at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93)
elastic_1   |   at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70)
elastic_1   |   at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:46)
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:213)
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:140)
elastic_1   |   at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
elastic_1   |   at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:45)
elastic_1   | Exception in thread "main" java.lang.NullPointerException
elastic_1   |   at java.io.Reader.<init>(Reader.java:78)
elastic_1   |   at java.io.InputStreamReader.<init>(InputStreamReader.java:97)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.loadMainDict(Dictionary.java:353)
elastic_1   |   at org.wltea.analyzer.dic.Dictionary.initial(Dictionary.java:149)
elastic_1   |   at org.wltea.analyzer.cfg.Configuration.<init>(Configuration.java:47)
elastic_1   |   at org.elasticsearch.indices.analysis.IKIndicesAnalysis.<init>(IKIndicesAnalysis.java:30)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
elastic_1   |   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
elastic_1   |   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
elastic_1   |   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
elastic_1   |   at <<<guice>>>
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:213)
elastic_1   |   at org.elasticsearch.node.Node.<init>(Node.java:140)
elastic_1   |   at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194)
elastic_1   |   at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
elastic_1   |   at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:45)

主要的原因是无法定位到 IKAnalyzer.cfg.xml 以及 main.dic,其搜索位置为:

但是我搜索后发现,这两个文件存在,但是位于 /etc/elasticsearch/analysis-ik/ 下:

$ find / -name IKAnalyzer.cfg.xml
/etc/elasticsearch/analysis-ik/IKAnalyzer.cfg.xml
$ find / -name main.dic
/etc/elasticsearch/analysis-ik/main.dic

我注意到 https://github.com/medcl/elasticsearch-analysis-ik/pull/197 应该允许加载 /etc/elasticsearch/analysis-ik/ 目录下的配置文件,不知道这里是不是有什么 bug,导致了这次问题。

medcl commented 7 years ago

使用 plugin命令安装会自动迁移配置,你可以调整 docker 配置,使用新路径,或者改变安装方式,解压到插件目录,手动安装

mxgit1090 commented 6 years ago

所以以下兩個檔案都有的話

$ES_PATH/config/analysis-ik/IKAnalyzer.cfg.xml
$ES_PATH/plugins/analysis-ik/config/IKAnalyzer.cfg.xml

IK 會優先用上面的路徑,下面的就會被忽略? 還是說兩個都會採用,只要他的 entry key 不一樣的話?