我正在尝试使用ElasticSearch 5.4.0创建ElasticSearch TransportClient。客户端创建如下:
@SuppressWarnings({ "resource", "unchecked" })
private static Client getTransportClient() {
try {
InetSocketTransportAddress inetAddress = new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300);
client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(inetAddress);
} catch (UnknownHostException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
return client;
}
现在,在运行时,我收到以下错误:
Exception in thread "main" java.lang.VerifyError: class org.elasticsearch.transport.Netty3Plugin overrides final method onModule.(Lorg/elasticsearch/common/network/NetworkModule;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:54)
at org.personal.elastic.twitter.ElasticUtil.getTransportClient(ElasticUtil.java:65)
at org.personal.elastic.twitter.ElasticUtil.indexTweet(ElasticUtil.java:42)
at org.personal.elastic.twitter.TweetHunter.main(TweetHunter.java:39)
从错误的角度看,似乎是一些依赖冲突问题(Netty3Plugin?)。在这方面,我想从我的pom.xml中为ElasticSearch和Transport客户端依赖项提供一个片段:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.0.0-beta1</version>
</dependency>
请告诉我,可能有什么问题(使用我的maven依赖项或API使用情况)?我可能会尝试回去使用旧版本的ElasticSearch(2.x,也许?),但是,我不想......帮助表示赞赏!