gpt4 book ai didi

java - Java 客户端尝试连接到 Elastic Search 时出错

转载 作者:行者123 更新时间:2023-11-30 08:31:48 24 4
gpt4 key购买 nike

使用以下代码尝试连接并索引到 Elastic Search:

package elasticSearchTest;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.net.InetAddress;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.testng.annotations.Test;

public class ES_Test_Class {
@Test
public void f() {
try{
Client client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));


IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", "18/May/2011:01:48:10")
.field("message", "trying out Elasticsearch")
.endObject()
)
.get();
// Document ID (generated or not)
String _id = response.getId();
// Version (if it's the first time you index this document, you will get: 1)
long _version = response.getVersion();

System.out.println("Document id is: "+_id);

System.out.println("Document version is: "+_version);
}
catch (Exception e){
e.printStackTrace();
}

}
}

具有以下依赖性:

  • 列表项

enter image description here

但是我一直收到以下错误:

com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: org/jboss/netty/channel/socket/nio/WorkerPool at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201) at com.google.common.cache.LocalCache.get(LocalCache.java:3937) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824) at org.elasticsearch.common.inject.internal.FailableCache.get(FailableCache.java:51) at org.elasticsearch.common.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:51) at org.elasticsearch.common.inject.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:50) at org.elasticsearch.common.inject.InjectorImpl.initializeBinding(InjectorImpl.java:405) at org.elasticsearch.common.inject.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:680)

我已经尝试通过更改 JAR 文件的顺序和不同版本的 JARS 来降低和更改为更高版本,如提到的一些建议 here但问题没有解决

将“netty”更新为“netty-4.0.0.Alpha8”并将 Guava 更新为“guava-20.0-hal”后出错:

com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: org/jboss/netty/channel/ReceiveBufferSizePredictorFactory at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) at com.google.common.cache.LocalCache.get(LocalCache.java:4054) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4058) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4985) at org.elasticsearch.common.inject.internal.FailableCache.get(FailableCache.java:51) at org.elasticsearch.common.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:51)

最佳答案

我猜 WorkerPool 类自版本 3.5 开始与 netty 一起使用。所以你需要更新你的 netty 版本至少到 3.5+。

关于java - Java 客户端尝试连接到 Elastic Search 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40462418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com