How to solve java.lang.NoSuchFieldError: LUCENE_7_7_2

Hi, I'm using the elasticsearch 7.6.2 and I'm trying to create an index and update the mappings in a second step. The index gets successfully created, however the mapping update fails with the following error:

nested exception is java.lang.NoSuchFieldError: LUCENE_7_7_2] with root cause
java.lang.NoSuchFieldError: LUCENE_7_7_2
	at org.elasticsearch.Version.<clinit>(Version.java:111)
	at org.elasticsearch.common.io.stream.StreamInput.<init>(StreamInput.java:113)
	at org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper.<init>(AbstractBytesReference.java:195)
	at org.elasticsearch.common.bytes.AbstractBytesReference$MarkSupportingStreamInputWrapper.<init>(AbstractBytesReference.java:189)

My code looks like that:

 private void createIndex(String indexname) {
  String indexname = "myIndex";
    try {
	  RestClientBuilder builder = RestClient.builder(new HttpHost(hostname, port, scheme));
      RestHighLevelClient client = new RestHighLevelClient(builder);
	  
      CreateIndexRequest indexRequest = new CreateIndexRequest(indexname);
      CreateIndexResponse createIndexResponse = client.indices()
          .create(indexRequest, RequestOptions.DEFAULT);
		  
      if (createIndexResponse.isAcknowledged()) {
		// Index gets created, proceed to update the mappings
        updateIndexMapping(client, indexname);
      }
    } catch (Exception e) {
      log.error("Unable to create the elasticsearch index : [" + e.getMessage() + "]");
    }
  }
  
  
  private void updateIndexMapping(RestHighLevelClient client, String indexname) {
    try {
      PutMappingRequest request = new PutMappingRequest(indexname);
      XContentBuilder builder = XContentFactory.jsonBuilder();
      builder.startObject();
      {
        builder.startObject("properties");
        {
          builder.startObject("date");
          {
            builder.field("type", "date");
          }
          {
            builder.field("format", "dd.MM.yyyy");
          }
          builder.endObject();
          builder.startObject("location");
          {
            builder.field("type", "geo_point");
          }
          builder.endObject();
        }
        builder.endObject();
      }
      builder.endObject();
      request.source(builder);

      if (!client.indices().putMapping(request, RequestOptions.DEFAULT).isAcknowledged()) {
		log.error(String.format("Unable to update the mappings for index %s.", indexname));		
      } else {
        log.info(String.format("Mappings for index %s successfully updated ", indexname));
        // Mappings updated, procced with saving a doc ..
      }
    } catch (Exception e) {
      log.error("Unable to update the index mappings : [" + e.getMessage() + "]");
    }
  }

My pom includes the elasticsearch version as a property
<elasticsearch.version>7.6.2</elasticsearch.version>

and I have both elasticsearch and elasticsearch.client as dependencies :

<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch</artifactId>
  <version>${elasticsearch.version}</version>
</dependency>
<dependency>
  <groupId>org.elasticsearch.client</groupId>
  <artifactId>elasticsearch-rest-high-level-client</artifactId>
  <version>${elasticsearch.version}</version>
</dependency>

Lucene is also present for other project purposes:
<lucene.version>8.1.1</lucene.version>

    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-core</artifactId>
      <version>${lucene.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.lucene</groupId>
      <artifactId>lucene-analyzers-common</artifactId>
      <version>${lucene.version}</version>
    </dependency>

mvn dependency:tree -Dverbose -Dincludes=org.apache.lucene Gives the following :

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

Our spring-boot-version is 2.3.0 if that helps. Any ideas on how to solve this problem? Thanks in advance

When using springboot with elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:

<properties>
  <elasticsearch.version>7.7.0<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions

Thanks for responding.
My problem was solved after upgrading to Lucene 8.5.2 .
I'm declaring the rest-high-level-client dependecy which uses the spring-boot elastic dependency. (Spring-boot 2.3.0 declares the elasticsearch 7.6.2 dependency )

<dependency>
  <groupId>org.elasticsearch.client</groupId>
  <artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>

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