我们需要将一个elasticsearch客户端包含到一个项目中,该项目本身使用Lucene进行其他索引/存储任务。包括整个库导致依赖冲突,因为Lucene版本不相同(ES使用4.7,我们使用4.0)。 是否有任何“仅限客户”的弹性搜索包,或者有人能想到任何其他解决方案吗?
修改
排除所有lucene包的方法导致以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
at org.elasticsearch.Version.<clinit>(Version.java:42)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:169)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:125)
at de.tensquare.wpt.entrysearchindex.ElasticSearchClient.<init>(ElasticSearchClient.java:74)
at de.tensquare.wpt.entrysearchindex.SearchIndex.<init>(SearchIndex.java:81)
at de.tensquare.wpt.entrysearchindex.SearchIndex.main(SearchIndex.java:152)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
答案 0 :(得分:1)
我最近遇到了类似的问题。我们的堆栈中有solr和elasticsearch。使用elasticserch传输客户端,我们遇到了lucence snafus。这是帮助我的解决方法。我创建了一个阴影jar,它改变了elasticsearch引用lucene和carrot搜索包的方式。
编辑:我遇到了另一个项目的问题,因此需要进一步深化,更新解决方案
elasticsearch wraper project pom
<?xml version="1.0"?>
<project .>
<parent>
<artifactId>someartifactId</artifactId>
<groupId>some.group.id</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>someartifactId-elasticsearch</artifactId>
<name>Some Artifact Elasticsearch</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/services/org.apache.lucene.codecs.Codec</exclude>
<exclude>META-INF/services/org.apache.lucene.codecs.DocValuesFormat</exclude>
<exclude>META-INF/services/org.apache.lucene.codecs.PostingsFormat</exclude>
<exclude>META-INF/services/org.apache.lucene.analysis.util.CharFilterFactory</exclude>
<exclude>META-INF/services/org.apache.lucene.analysis.util.TokenFilterFactory</exclude>
<exclude>META-INF/services/org.apache.lucene.analysis.util.TokenizerFactory</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.</pattern>
<shadedPattern>hack.org.</shadedPattern>
</relocation>
<relocation>
<pattern>com.</pattern>
<shadedPattern>hack.com.</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
hack.org.apache.lucene.analysis.util.CharFilterFactory
hack.org.apache.lucene.analysis.util.TokenFilterFactory
hack.org.apache.lucene.codecs.Codec
hack.org.apache.lucene.codecs.DocValuesFormat
hack.org.apache.lucene.codecs.PostingsFormat
hack.org.apache.lucene.analysis.util.TokenizerFactory
现在使用TransportClient(或任何其他弹性搜索类)使用包 hack.org.elasticsearch ....
答案 1 :(得分:0)
在类路径中包含elasticsearch.1.1.0.jar和lucune.4.7.jar。它足以运输客户端。
它有帮助......!