试试搜索一下吧

修改Lucene源码,重新打包,替换elasticsearch中原有的Lucene-core.jar包,出现问题

Elasticsearch | 作者 elisha | 发布于2017年12月21日 | 阅读数:6959

(elasticsearch版本2.4.5,Lucene-core版本5.5.4)
 
修改Lucene源码(maven工程),重新打包,替换elasticsearch中原有的Lucene-core.jar包,出现以下错误:java.util.ServiceConfigurationError: Cannot instantiate SPI class: org.apache.lucene.codecs.lucene50.Lucene50Codec
        at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:82)
        at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:51)
        at org.apache.lucene.util.NamedSPILoader.<init>(NamedSPILoader.java:38)
        at org.apache.lucene.codecs.Codec$Holder.<clinit>(Codec.java:47)
        at org.apache.lucene.codecs.Codec.reloadCodecs(Codec.java:133)
        at org.elasticsearch.plugins.PluginsService.reloadLuceneSPI(PluginsService.java:454)
        at org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:430)
        at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:115)
        at org.elasticsearch.node.Node.<init>(Node.java:158)
        at org.elasticsearch.node.Node.<init>(Node.java:140)
        at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:286)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:45)
Caused by: java.lang.IllegalArgumentException: An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'Lucene50' does not exist.  You need to add the corresponding JAR file supporting this SPI to your classpath.  The current classpath supports the following names: [es090, completion090, XBloomFilter, Lucene40, Lucene41, IDVersion, completion]
        at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:114)
        at org.apache.lucene.codecs.PostingsFormat.forName(PostingsFormat.java:112)
        at org.apache.lucene.codecs.lucene50.Lucene50Codec.<init>(Lucene50Codec.java:155)
        at org.apache.lucene.codecs.lucene50.Lucene50Codec.<init>(Lucene50Codec.java:75)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at java.lang.Class.newInstance(Class.java:374)
        at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:72)
        ... 13 more
已邀请:

Kalasearch

赞同来自:

请问你是在打包fat jar的过程中出现的问题吗?
 
Lucene里的lucene-suggest和elastic中的META-INF/services需要合并一下,如果你用的是Maven的话,请添加:
	<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/org.apache.lucene.codecs.Codec</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/org.apache.lucene.codecs.DocValuesFormat</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/org.apache.lucene.codecs.PostingsFormat</resource>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>fat</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
如果你用的是gradle的话,可以用shadowJar
shadowJar {
append 'META-INF/services/org.apache.lucene.codecs.PostingsFormat'
append 'META-INF/services/org.apache.lucene.codecs.DocValuesFormat'
append 'META-INF/services/org.apache.lucene.codecs.Codec'
}

 
请参考以下文章:
https://github.com/elastic/ela ... 15071
https://github.com/elastic/ela ... /3350
 

要回复问题请先登录注册