【问题标题】:Error while Java client trying to connect to Elastic SearchJava 客户端尝试连接到 Elastic Search 时出错
【发布时间】:2016-11-07 10:02:44
【问题描述】:

我正在尝试使用以下代码连接并索引到 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();
      }

  }
}

具有以下依赖项:

  • 列表项

但是我不断收到以下错误:

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

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

将“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 在 com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) 在 com.google.common.cache.LocalCache.get(LocalCache.java:4054) 在 com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4058) 在 com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4985) 在 org.elasticsearch.common.inject.internal.FailableCache.get(FailableCache.java:51) 在 org.elasticsearch.common.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:51)

【问题讨论】:

    标签: java elasticsearch netty guava guice


    【解决方案1】:

    WorkerPool 类与 netty 自版本 3.5 我猜想。所以你需要将你的netty版本更新到至少3.5+。

    【讨论】:

    • 将你的netty更新到4+以下。错误类在 3.9 之后不存在。
    • 当然,将尝试使用 3.8
    • 对于更一般的评论,错误 NoClassDefFoundError 指定在您的类路径中找不到相应的类。从包名中你可以找到相关的库,在这种情况下它显然是 netty。通过 google 搜索,不难找到包含缺失类的版本。希望下次再遇到这种情况时能有所帮助。
    猜你喜欢
    • 2022-11-07
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多