简体   繁体   中英

Erro: java.lang.NoSuchFieldError: LUCENE_5_2_1

Am trying to Index to elastic search using java API and later use that data for visualisation in Kibana as below:

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();
      }

  }
}

Below are the updated dependencies:

在此处输入图片说明

However when I run the code I get below error:

[TestNG] Running: C:\\Users\\vinbhask\\AppData\\Local\\Temp\\testng-eclipse--931338640\\testng-customsuite.xml Nov 04, 2016 9:03:52 PM org.elasticsearch.plugins.PluginsService INFO: [Kismet] modules [], plugins [], sites [] FAILED: f java.lang.NoSuchFieldError: LUCENE_5_2_1 at org.elasticsearch.Version.(Version.java:265) at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:129) at elasticSearchTest.ES_Test_Class.f(ES_Test_Class.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Inv oker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

I tried googling for the solution and came across this link and this link but could not understand how to resolve the issue, I had even rebuilt the project by adding one JAR at a time but of no help

[Update]: After adding lucene 5.5.2 jar getting below error:

[TestNG] Running: C:\\Users\\vinbhask\\AppData\\Local\\Temp\\testng-eclipse--545647994\\testng-customsuite.xml Nov 06, 2016 9:18:20 AM org.elasticsearch.plugins.PluginsService INFO: [Locus] modules [], plugins [], sites [] FAILED: f java.lang.NoSuchMethodError: org.jboss.netty.channel.socket.nio.NioWorkerPool.(Ljava/util/concurrent/Executor;I)V at org.elasticsearch.transport.netty.NettyTransport.createClientBootstrap(NettyTransport.java:354) at org.elasticsearch.transport.netty.NettyTransport.doStart(NettyTransport.java:290) at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68) at org.elasticsearch.transport.TransportService.doStart(TransportService.java:182) at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68) at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:162) at elasticSearchTest.ES_Test_Class.f(ES_Test_Class.java:17) at sun.reflect.NativeMeth odAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)

You are using Lucene 4.10.4, but Elasticsearch 2.4.1 is based on Lucene 5.5.2. Upgrade your Lucene version ( 5.5.2 is here ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM