Skip to content

NoClassDefFound after migrating to Elasticsearch 9.0.2 #1036

Open
@FelixHerz

Description

@FelixHerz

Java API client version

9.0.2

Java version

21

Elasticsearch Version

9.0.2

Problem description

I am currently migrating our service from Elasticsearch 8.18.2 to 9.0.2.

Unfortunately I get a

Caused by: java.lang.NoClassDefFoundError: org/apache/hc/client5/http/ConnectTimeoutException
	at co.elastic.clients.transport.rest5_client.Rest5ClientTransport.buildRest5Client(Rest5ClientTransport.java:65)
	at co.elastic.clients.transport.rest5_client.Rest5ClientTransport.<init>(Rest5ClientTransport.java:42)
	at co.elastic.clients.transport.ElasticsearchTransportConfig$Default.buildTransport(ElasticsearchTransportConfig.java:110)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.of(ElasticsearchClient.java:188)

When starting the Service.


To give you a little context, elastichsearch is wrapped in our own search library:

The pom regarding elasticsearch looks as following:

 <dependencies>
        <!-- Elasticsearch Java API Client -->
        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
        </dependency>

        <!-- Quite a few more dependencies -->

  </dependencies>

Mvn Dependency Tree gives us:

%  mvn dependency:tree -Dincludes=org.apache.httpcomponents
...
[INFO] --- dependency:3.8.1:tree (default-cli) @ skw-pcs-search-elasticsearch ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

However, when I analyse the dependencies in Intellij it says:

Analysed Dependencies

There is a spring boot test in there, which tests against a elasticsearch testcontainer. That test is successfull. All good so far.


The library is then used in the service. This is where it all breaks. The maven build is successful but when starting up the service, I get the NoClassDefFound error from above.

Again, mvn dependency:tree doesn't show anything for -Dincludes=org.apache.httpcomponents.

However, I explicitly added it in the pom;

        <dependency>
            <groupId>org.apache.httpcomponents.core5</groupId>
            <artifactId>httpcore5</artifactId>
            <version>5.3.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.5</version>
        </dependency>

Elasticsearch client is created with:

  @Bean
  public ElasticsearchClient elasticsearchClient(PcsSearchIndexSettings settings) {
    return ElasticsearchClient.of(builder -> builder
                    .host("%s://%s:%d".formatted(
                            settings.getProtocol(),
                            settings.getHost(),
                            settings.getPort()))
    );
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions