Elasticsearch安装自定义插件导致错误:插件zip中缺少`elasticsearch`目录

时间:2017-08-31 17:35:41

标签: elasticsearch elasticsearch-plugin

当我尝试安装我通过调用

构建的插件时
./elasticsearch-plugin install file:///fullpath/to/zipfile/custome_plugin.zip

它给了我这个错误:

ERROR: `elasticsearch` directory is missing in the plugin zip

我正在阅读其他类似帖子,许多人试图安装.jar而不是.zip。我确实尝试安装.zip,但同样的错误仍然显示。

此外(可能与此问题无关),当我手动解压缩zip文件并将其放入插件文件夹时,执行elasticsearch-plugins list会列出自定义插件。在这种情况下,插件是一个自定义分析器,但不知何故映射无法识别分析器。是因为我没有正确安装吗?

编辑:

添加一些信息,当我关闭群集然后在手动解压缩插件并将其放入plugin目录后重新启动时,群集将无法启动。我收到的错误似乎是

[2017-08-31T11:15:52,668][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] fatal error in thread [main], exiting
java.lang.NoClassDefFoundError: org/elasticsearch/index/analysis/AnalysisModule$AnalysisBinderProcessor
    at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.8.0_65]
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[?:1.8.0_65]
    at java.lang.Class.getConstructor0(Class.java:3075) ~[?:1.8.0_65]
    at java.lang.Class.getConstructor(Class.java:1825) ~[?:1.8.0_65]
    at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:423) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:387) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:140) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.node.Node.<init>(Node.java:312) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.node.Node.<init>(Node.java:244) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:232) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:232) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.2.jar:5.5.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.2.jar:5.5.2]
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.index.analysis.AnalysisModule$AnalysisBinderProcessor
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_65]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_65]
    at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:814) ~[?:1.8.0_65]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_65]
    ... 19 more

好像这个分析

是否有一些我遗失的图书馆?

编辑2: 经过一番挖掘,我找到了这个网站

http://snacktrace.com/artifacts/org.elasticsearch/elasticsearch/1.7.3/org.elasticsearch.index.analysis.AnalysisModule $ $ AnalysisBinderProcessor AnalyzersBindings

似乎这样AnalyzersBindings仅适用于ES 1.x和2.x(&lt; 2.4)?我需要一种方法来取代它。

编辑3: 根据要求,这里是如何使用AnalyzerBinding

package org.elasticsearch.plugin.analysis.my.analyzer;

import org.elasticsearch.index.analysis.AnalysisModule;

public class AnalyzerBinderProcessor extends AnalysisModule.AnalysisBinderProcessor {

    @Override
    public void processAnalyzers(AnalyzersBindings analyzersBindings) {
        analyzersBindings.processAnalyzer("my_name", AnalyzerProvider.class);
    }

    @Override
    public void processTokenFilters(TokenFiltersBindings tokenFiltersBindings) {
    }
}

然后在我的AnalyzerPlugin.java中我有

public class AnalyzerPlugin extends Plugin {
    //some other code here that's not related to Binder 

    public void onModule(AnalysisModule module) {
        module.addProcessor(new AnalyzerBinderProcessor());
    }
}

编辑4:这是无休止的.......

如果我保留@Override,它会抛出

[ERROR] /opt/bg/analytics/src/java/src/analyzer5.0/src/main/java/org/elasticsearch/plugin/analysis/my_analyzer/AnalyzerPlugin.java:[16,5] method does not override or implement a method from a supertype

另外,面对

的问题
[ERROR] /opt/bg/analytics/src/java/src/analyzer5.0/src/main/java/org/elasticsearch/plugin/analysis/my_analyzer/AnalyzerPlugin.java:[36,17] onModule(org.elasticsearch.indices.analysis.AnalysisModule) in org.elasticsearch.plugin.analysis.my_analyzer.AnalyzerPlugin cannot override onModule(org.elasticsearch.indices.analysis.AnalysisModule) in org.elasticsearch.plugins.Plugin

因为overridden method is final

这是从旧版Plugin到新版本的更新吗?我迷路了......

我觉得我需要一个关于如何为自定义分析器创建插件的全面教程,到目前为止我能找到的就是这个

http://david.pilato.fr/blog/2016/10/16/creating-a-plugin-for-elasticsearch-5-dot-0-using-maven-updated-for-ga/

这没有多大帮助。有人有很好的联系吗?

2 个答案:

答案 0 :(得分:3)

看起来您已经修复了错误。

但是,我想我会加上我的学习,以防有人因为我犯的错误而ERROR: 'elasticsearch' directory is missing in the plugin zip。{/ p>

正如Elasticsearch文档(https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html)中所述,在将文件夹压缩为zip文件之前,插件的文件夹名称应为“elasticsearch”。

因此,无论zip文件的名称如“elasticsearch-analysis-mecab-ko-5.5.3.0.zip”,压缩前​​的插件文件夹都应称为“elasticsearch”。如果文件夹名称不是“elasticsearch”,那么当您运行elasticsearch-plugin install时,您的elasticsearch只会为您提供ERROR: 'elasticsearch' directory is missing in the plugin zip

因此,在您制作或修改自定义插件文件夹后,请将其压缩:

$ zip -r elasticsearch-analysis-mecab-ko-5.5.3.0.zip elasticsearch

然后安装插件

$ ./elasticsearch-plugin install file:///Users/btaek/Desktop/ElasticSearch/elasticsearch-analysis-mecab-ko-5.5.3.0.zip

答案 1 :(得分:1)

目前,在ES 5.x中我们有org.elasticsearch.plugins.AnalysisPlugin,这是创建自定义分析组件的要点。您需要调整您的插件代码,以便您可以注册您拥有的任何自定义分析器/标记器/等。

插件示例,应该为您解决问题:

public class MyAnalyzerPlugin implements AnalysisPlugin {

@Override
public Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> getAnalyzers() {
    final Map<String, AnalysisModule.AnalysisProvider<AnalyzerProvider<? extends Analyzer>>> objectObjectHashMap = new HashMap<>();
    objectObjectHashMap.put("my_analyzer", new MyAnalyzerProviderFactory());
    return objectObjectHashMap;
}

class MyAnalyzerProviderFactory implements AnalysisModule.AnalysisProvider<AnalyzerProvider<?>> {

    private final MyAnalyzerProvider analyzerProvider;

    public MyAnalyzerProviderFactory() {
        analyzerProvider = new MyAnalyzerProvider(AnalyzerScope.INDICES);
    }

    public AnalyzerProvider<?> create(String name, Settings settings) {
        Version indexVersion = Version.indexCreated(settings);
        if (!Version.CURRENT.equals(indexVersion)) {
            PreBuiltAnalyzers preBuiltAnalyzers = PreBuiltAnalyzers.getOrDefault(name, null);
            if (preBuiltAnalyzers != null) {
                Analyzer analyzer = preBuiltAnalyzers.getAnalyzer(indexVersion);
                return new MyAnalyzerProvider(AnalyzerScope.INDICES);
            }
        }

        return analyzerProvider;
    }

    @Override
    public AnalyzerProvider<?> get(IndexSettings indexSettings, Environment environment, String name, Settings settings)
            throws IOException {
        return create(name, settings);
    }

    public Analyzer analyzer() {
        return analyzerProvider.get();
    }
}


class MyAnalyzerProvider implements AnalyzerProvider<StandardAnalyzer> {

    private final StandardAnalyzer analyzer;
    private final AnalyzerScope scope;

    public MyAnalyzerProvider(AnalyzerScope scope) {
        this.scope = scope;
        this.analyzer = new StandardAnalyzer();
    }

    @Override
    public String name() {
        return "my-standard-analyzer";
    }

    @Override
    public AnalyzerScope scope() {
        return scope;
    }

    @Override
    public StandardAnalyzer get() {
        return analyzer;
    }
}

当然,您也需要调整分析器,因为Lucene版本已更改,某些API可能已被弃用或删除。