简体   繁体   English

Maven中的Elasticsearch“仅客户端”依赖项

[英]Elasticsearch “Client only” dependency in Maven

We need to include a elasticsearch client into a project which itself uses Lucene for other indexing/storage tasks. 我们需要将Elasticsearch客户包含到一个项目中,该项目本身使用Lucene来执行其他索引/存储任务。 Including the whole library results in a dependency conflict because the Lucene versions are not the same (ES uses 4.7, we use 4.0). 包括整个库会导致依赖项冲突,因为Lucene版本不相同(ES使用4.7,我们使用4.0)。 Is there any "client only" package of elasticsearch or does anybody can think of any other solution? 有没有Elasticsearch的“仅客户端”软件包,或者有人可以考虑其他解决方案吗?

Edit: 编辑:

The approach to exclude all the lucene packages resulted in the following error: 排除所有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)

I recently ran into similar issues. 我最近遇到了类似的问题。 We have both solr and elasticsearch in our stack. 我们的堆栈中同时包含solr和elasticsearch。 Using elasticserch transport client, we were ran into lucence snafus. 使用Elasticserch运输客户端,我们遇到了Lucence瘫痪。 Here is the workaround that helped me. 这是对我有帮助的解决方法。 I created a shaded jar that changes how elasticsearch references lucene and carrot search packages. 我创建了一个有阴影的罐子,该罐子改变了Elasticsearch引用lucene和胡萝卜搜索包的方式。

EDIT : I ran into issue from another project, so needed to shade a bit further, updated solution 编辑 :我遇到了另一个项目的问题,所以需要阴影一点,更新的解决方案

elasticsearch wraper project pom elasticsearch包装项目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>

In src/main/resources/META-INF/services, create shaded filters and codecs that get packaged up 在src / main / resources / META-INF / services中,创建被打包的阴影过滤器和编解码器

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

Now to use the TransportClient (or any other elastic search class) use package hack.org.elasticsearch.... 现在要使用TransportClient(或任何其他弹性搜索类),请使用hack.org.elasticsearch软件包。

Include elasticsearch.1.1.0.jar and lucune.4.7.jar in class path. 在类路径中包含elasticsearch.1.1.0.jar和lucune.4.7.jar。 its enough for transport Client. 它足以运输客户。

HOpe it helps..! 希望能帮助到你..!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM