NoClassDefFoundError exception with SpringBoot in Elasticsearch7.3

Hi!
I try to create document via high level rest client with:

Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("name", "Bob");
jsonMap.put("id", "123456");
IndexRequest indexRequest = new IndexRequest("lead").id("123456").source(jsonMap);
client.index(indexRequest, RequestOptions.DEFAULT);

But it throws a NoClassDefFoundError: org/apache/lucene/util/BytesRefIterator.
The elastic version is 7.3.2.

That's the elasticsearch dependency in my pom.

            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>7.3.2</version>
            </dependency>
            <dependency>
                <groupId>org.elasticsearch.client</groupId>
                <artifactId>elasticsearch-rest-high-level-client</artifactId>
                <version>7.3.2</version>
            </dependency>
The full stacktrace:
Exception in thread "Thread-20" java.lang.NoClassDefFoundError: org/apache/lucene/util/BytesRefIterator
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:397)
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:377)
	at org.elasticsearch.action.index.IndexRequest.source(IndexRequest.java:365)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.createDocument(MetadataDocumentBuilderImpl.java:182)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.build(MetadataDocumentBuilderImpl.java:76)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getPage(MetadataDocumentBuilderImpl.java:163)
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getSyncMetadata(MetadataDocumentBuilderImpl.java:121)
	at com.sunyard.mdhome.thread.MetadataSyncThread.run(MetadataSyncThread.java:30)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.BytesRefIterator
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 9 more

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

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.3.0<elasticsearch.version>
</properties>

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

Hi, I've already declared the elasticsearch version 7.3.2 in the pom.xml. But the error still exists.

Could you run

mvn dependency:tree

Hi, I've formatted my code in markdown syle. So it'll be easier to be read.

According to your advice, I've found out the cause of the error. There's another dependence in this project which includes a 3.5.0 version of lucene-core.jar. It conflicts with the 8.1.0 version lucene-core.jar in elasticsearch. The program uses the 3.5.0 version actually while the program is running.

Although I haven't worked out how to fix the version confilict by not influencing the formmer module, the cause of the error is clear now. Thanks a lot.

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