How to solve java.lang.NoSuchFieldError: LUCENE_5_2_1

So I'm running elasticsearch 6.3.1 under a maven project with no other dependencies than

<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>6.3.1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
 </dependency>

Here are my codes to initiate the client with java api:

Settings settings = Settings.builder()
        .put("cluster.name","elasticsearch")
        .build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddresses.forString("127.0.0.1"), 9300));

And with so many tries including manually adding lucene version into dependencies, I am still getting this error:
java.lang.NoSuchFieldError: LUCENE_5_2_1

My codes works perfectly for es5.1.2 and I thought it would be the same to 6.3.1 but it seems to be different more than just the version number.Any suggestions will be appreciated and thanks in advance.

Could you run

mvn dependency:tree

Thanks for replying at this moment, below is what I got

D:\workspace\ElasticSearchTest>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ElasticSearchTest Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ ElasticSearchTest ---
[INFO] com.zzc:ElasticSearchTest:war:1.0-SNAPSHOT
[INFO] +- org.elasticsearch.client:transport:jar:6.3.1:compile
[INFO] |  +- org.elasticsearch:elasticsearch:jar:6.3.1:compile
[INFO] |  |  +- org.elasticsearch:elasticsearch-core:jar:6.3.1:compile
[INFO] |  |  +- org.elasticsearch:elasticsearch-secure-sm:jar:6.3.1:compile
[INFO] |  |  +- org.elasticsearch:elasticsearch-x-content:jar:6.3.1:compile
[INFO] |  |  |  +- org.yaml:snakeyaml:jar:1.17:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.10:compile
[INFO] |  |  |  \- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.10:compile
[INFO] |  |  +- org.apache.lucene:lucene-analyzers-common:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-backward-codecs:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-grouping:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-highlighter:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-join:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-memory:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-misc:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queryparser:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-sandbox:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial-extras:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial3d:jar:7.3.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-suggest:jar:7.3.1:compile
[INFO] |  |  +- org.elasticsearch:elasticsearch-cli:jar:6.3.1:compile
[INFO] |  |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO] |  |  +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] |  |  +- joda-time:joda-time:jar:2.9.9:compile
[INFO] |  |  +- com.tdunning:t-digest:jar:3.2:compile
[INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-api:jar:2.9.1:compile
[INFO] |  |  \- org.elasticsearch:jna:jar:4.5.1:compile
[INFO] |  +- org.elasticsearch.plugin:transport-netty4-client:jar:6.3.1:compile
[INFO] |  |  +- io.netty:netty-buffer:jar:4.1.16.Final:compile
[INFO] |  |  +- io.netty:netty-codec:jar:4.1.16.Final:compile
[INFO] |  |  +- io.netty:netty-codec-http:jar:4.1.16.Final:compile
[INFO] |  |  +- io.netty:netty-common:jar:4.1.16.Final:compile
[INFO] |  |  +- io.netty:netty-handler:jar:4.1.16.Final:compile
[INFO] |  |  +- io.netty:netty-resolver:jar:4.1.16.Final:compile
[INFO] |  |  \- io.netty:netty-transport:jar:4.1.16.Final:compile
[INFO] |  +- org.elasticsearch.plugin:reindex-client:jar:6.3.1:compile
[INFO] |  |  \- org.elasticsearch.client:elasticsearch-rest-client:jar:6.3.1:compile
[INFO] |  |     +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  |     +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] |  |     +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  +- org.elasticsearch.plugin:lang-mustache-client:jar:6.3.1:compile
[INFO] |  |  \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] |  +- org.elasticsearch.plugin:percolator-client:jar:6.3.1:compile
[INFO] |  +- org.elasticsearch.plugin:parent-join-client:jar:6.3.1:compile
[INFO] |  \- org.elasticsearch.plugin:rank-eval-client:jar:6.3.1:compile
[INFO] +- junit:junit:jar:4.12:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] \- org.apache.lucene:lucene-core:jar:7.3.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.301 s
[INFO] Finished at: 2018-07-30T11:40:13+08:00
[INFO] Final Memory: 18M/385M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "default" could not be activated because it does not exist.

And with "mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene" I got:

[INFO] +- org.elasticsearch.client:transport:jar:6.3.1:compile
[INFO] |  \- org.elasticsearch:elasticsearch:jar:6.3.1:compile
[INFO] |     +- (org.apache.lucene:lucene-core:jar:7.3.1:compile - omitted for duplicate)
[INFO] |     +- org.apache.lucene:lucene-analyzers-common:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-backward-codecs:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-grouping:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-highlighter:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-join:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-memory:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-misc:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-queries:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-queryparser:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-sandbox:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-spatial:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-spatial-extras:jar:7.3.1:compile
[INFO] |     +- org.apache.lucene:lucene-spatial3d:jar:7.3.1:compile
[INFO] |     \- org.apache.lucene:lucene-suggest:jar:7.3.1:compile
[INFO] \- org.apache.lucene:lucene-core:jar:7.3.1:compile

Did you manually add the Lucene core jar in your pom?
Could you share the full pom?

Yes I manually added the lucene dependencies and it gives the same error with/without that.

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.zzc</groupId>
  <artifactId>ElasticSearchTest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>ElasticSearchTest Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <repositories>
    <repository>
      <id>elasticsearch-releases</id>
      <url>https://artifacts.elastic.co/maven</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>6.3.1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <!--<dependency>-->
      <!--<groupId>org.apache.lucene</groupId>-->
      <!--<artifactId>lucene-core</artifactId>-->
      <!--<version>7.3.1</version>-->
    <!--</dependency>-->
  </dependencies>
  <build>
    <finalName>ElasticSearchTest</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
      </plugins>
    </pluginManagement>
  </build>
</project>

Problem solved
I was using :
"new InetSocketTransportAddress...." which causes the error because for es 6.3 it has to be replaced by
"new TransportAddress..."
Hope this can help people with similar error so they dont struggle hours like I did.
Still, thanks David.

Great. BTW you should use at least java8 I think.
And you should move to the rest client instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.