NoClassDefFoundError exception with SpringBoot in Elasticsearch7.3

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.

The full stacktrace:
Exception in thread "Thread-20" java.lang.NoClassDefFoundError: org/apache/lucene/util/BytesRefIterator
	at org.elasticsearch.action.index.IndexRequest.source(
	at org.elasticsearch.action.index.IndexRequest.source(
	at org.elasticsearch.action.index.IndexRequest.source(
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.createDocument(
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getPage(
	at com.sunyard.mdhome.elasticsearch.impl.MetadataDocumentBuilderImpl.getSyncMetadata(
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.BytesRefIterator
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	... 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:


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:


See documentation here:

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.