Using ElasticSearch and Lucene getting Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_7_2_1

I am using the following dependencies-

<dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>7.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-join</artifactId>
            <version>7.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>6.2.3</version>
          </dependency>

Get the exception as

Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_7_2_1
at org.elasticsearch.Version.<clinit>(Version.java:152)
at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:159)
at org.elasticsearch.common.ParseField.<clinit>(ParseField.java:35)
at org.elasticsearch.client.RestHighLevelClient.lambda$getDefaultNamedXContents$47(RestHighLevelClient.java:673)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1691)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.elasticsearch.client.RestHighLevelClient.getDefaultNamedXContents(RestHighLevelClient.java:674)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:215)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:200)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:192)

Know there are similar questions and it is about lucene dependency issue. But i am not able to get the dependencies right. Any help is appreciated. Thanks

1 answer

  • answered 2018-11-07 19:28 femtoRgon

    You are using three versions of lucene here, 7.1.0, 7.2.0, and Elasticsearch 6.2.3 would be at version 7.2.1.

    You should use the same version for all of these, so change the version of your lucene-core and lucene-join dependencies to 7.2.1.