2017-08-31 50 views
0

當我嘗試通過調用Elasticsearch安裝在錯誤自定義插件結果:`elasticsearch`目錄在插件ZIP失蹤

./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(< 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/

這並沒有多大幫助。有沒有人有一個很好的鏈接?

+1

是插件ü試圖安裝一個網站的插件?從5.0版開始,elasticsearch不再支持站點插件,所以這不起作用,請檢查https://www.elastic.co/blog/running-site-plugins-with-elasticsearch-5-0。 – skm

+0

@skm不是。這是一個自定義分析器。我從遺留代碼得到它,它是2.0,我試圖爲5.0構建它。分析器在我'mvn package'構建時生成,但它不能很好地集成或無法安裝)在5.0上。 – JChao

回答

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可以被棄用或刪除。

+0

感謝您的幫助(偉大的用戶名btw),我認爲我的主要問題是'AnalyzersBindings'不存在了。我們的遺留代碼有一個完整的文件利用這個。我一直在比較ES提供的分析儀的新舊版本(例如icu),以瞭解它們在5.x時發生了什麼變化。到目前爲止,我還沒有找到聯繫。你有什麼經驗? – JChao

+0

你能告訴你如何使用AnalyzersBindings? – Mysterion

+0

請在我的崗位 – JChao

2

看起來你已經修復了你的錯誤。

不過,我想我會加上我學習的情況下,還有誰也越來越ERROR: 'elasticsearch' directory is missing in the plugin zip becasue我犯同樣的錯誤的人。

正如在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-插件安裝,您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