NoClassDef org.apache.lucene.util.Version

I'm using the java client 7.17.6, with gradle to build the project;

implementation ("co.elastic.clients:elasticsearch-java:$elasticVersion")
implementation ("org.elasticsearch:elasticsearch-x-content:$elasticVersion")

Gradle grabs all of the required dependencies including the org.elasticsearch:elasticsearch:7.17.6.

Using the XContent component throws this stacktrace;

Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
        at org.elasticsearch.common.xcontent.XContentElasticsearchExtension.getXContentWriters(XContentElasticsearchExtension.java:67)
        at org.elasticsearch.xcontent.XContentBuilder.<clinit>(XContentBuilder.java:114)
        at org.elasticsearch.xcontent.json.JsonXContent.contentBuilder(JsonXContent.java:38)
        at org.elasticsearch.xcontent.XContentFactory.contentBuilder(XContentFactory.java:107)
        at org.elasticsearch.xcontent.XContentFactory.jsonBuilder(XContentFactory.java:34)

I can see the package "org.apache.lucene.util" does indeed exist in the org.elasticsearch:elasticsearch:7.17.6 jar, but not the "Version" class.

Is there another dependency the documentation hasn't mentioned I should be including?
Many thanks.

Welcome!

Why are you adding this line?

implementation ("org.elasticsearch:elasticsearch-x-content:$elasticVersion")

Documentation says:

dependencies {
    implementation 'co.elastic.clients:elasticsearch-java:7.17.6'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
}

I'm transitioning from the rest client where we are using the XContent component, my easiest first step is to simply switch out the client transport from REST to Java client.

Therefore for now I still need the XContent.
Oh and I do already have databind on the classpath.

I wonder how the org.elasticsearch:elasticsearch:7.17.6 jar compiles?

Line 67 of org.elasticsearch.common.xcontent.XContentElasticsearchExtension in that jar file;

writers.put(org.apache.lucene.util.Version.class, (b, v) -> b.value(Objects.toString(v)));

References a "org.apache.lucene.util.Version" class that doesn't appear to exist in the list of dependencies for that project.

-- EDIT
Ok, so lucene-core is required for compilation which I can see in Maven, so that answers how this compiles.

Perhaps I just can't use XContent with the Java client without having to specify additional dependencies?

Including lucene-core:8.11.1 seems to have gotten me over the hump for anyone else who happens to be doing anything like this in future. Whether this is the right thing to do or not, I don't know.

implementation ("org.apache-lucene:lucene-core:8.11.1")

Don't use anymore elasticsearch server internal classes like XContent.

You should switch totally to the new client instead. One of the goal of the new client is to get rid of the Lucene dependencies :wink:

Makes sense.

Thanks.

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