2

With below code am trying to connect and index to 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();
      }

  }
}

With below dependencies:

  • List item

enter image description here

However I keep getting below error:

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)

I have tried by changing the order of the JAR files and different versions of JARS lowering and changing to higher version by few of the suggestions as mentioned here but issue is not resolved

Error after updating "netty" to "netty-4.0.0.Alpha8" and guava to "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)

Community
  • 1
  • 1
Vinod
  • 376
  • 2
  • 11
  • 34

1 Answers1

2

The WorkerPool class is comming with netty since version 3.5 I guess. So you need to update your netty version to at least 3.5+.

alpert
  • 4,500
  • 1
  • 17
  • 27
  • Update your netty to something below 4+. Class in error does not exists after version 3.9. – alpert Nov 07 '16 at 12:59
  • Sure, will try with 3.8 – Vinod Nov 07 '16 at 14:07
  • For a more general comment the error NoClassDefFoundError specify that the corresponding class is not found in your classpath. From package name you can find the related library in this case it is obviously netty. And with a google search it is not too hard to find which versions include the missing class. Hope this will help next time you encounter such a case again. – alpert Nov 08 '16 at 06:35