我正在嘗試使用Elastic Search的文檔來從它的java Api中獲取和發佈數據。但我不斷收到錯誤。使用Java Api訪問彈性搜索
這是我現在試過的代碼。
Settings settings = Settings.builder().put("twitter", "tweet").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));
GetResponse response = client.prepareGet("twitter", "tweet", "1").get();
堆棧跟蹤
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableSortedMap at com.c1x.entity.Test.main(Test.java:20) Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableSortedMap at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more
請幫幫忙,我是新來的彈性搜索,該數據存在於彈性搜索,因爲我可以看到它時,我在kibana使用開發工具
添加谷歌共享後
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
at org.elasticsearch.common.settings.Settings$Builder.<init>(Settings.java:676)
at org.elasticsearch.common.settings.Settings$Builder.<clinit>(Settings.java:671)
at org.elasticsearch.common.settings.Settings.<clinit>(Settings.java:84)
at com.c1x.entity.Test.main(Test.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.SetOnce
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
添加lucene jar後
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
at org.elasticsearch.common.Strings.<clinit>(Strings.java:459)
at org.elasticsearch.common.settings.Settings.<init>(Settings.java:90)
at org.elasticsearch.common.settings.Settings$Builder.build(Settings.java:1215)
at com.c1x.entity.Test.main(Test.java:21)
另一個錯誤
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:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:84)
at com.c1x.entity.Test.main(Test.java:22)
抱歉再次打擾你@Jens,我是新的彈性搜索再次與代碼的一些問題,請檢查更新的問題。 – INFOSYS
@INFOSYS看起來像'elasticsearch'和'google-collections'的不兼容版本 – Jens
我如何檢查我的彈性搜索版本是5.4.0,並且google收藏與您提供的相同 – INFOSYS