Caused by: java.lang.NoSuchMethodError: 'void co.elastic.clients.transport.rest_client.RestClientTransport.<init>

Maven build is failing with no method found error.

Caused by: java.lang.NoSuchMethodError: 'void co.elastic.clients.transport.rest_client.RestClientTransport.<init>

Here is the pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ap.search</groupId>
    <artifactId>search-by-phone</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>search-by-phone</name>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.17.11</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.17.2</version>
        </dependency>
        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>8.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>jakarta.json</groupId>
            <artifactId>jakarta.json-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

You are missing 2 clients with 2 different versions.

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.17.11</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.17.2</version>
        </dependency>
        <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>8.9.0</version>
        </dependency>

Please look at what is needed in the documentation.

I am now using this, and still same error. Can you please tell me if I need to remove some extra dependency?

<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-high-level-client</artifactId>
			<version>7.17.11</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>7.17.11</version>
		</dependency>
		<dependency>
			<groupId>co.elastic.clients</groupId>
			<artifactId>elasticsearch-java</artifactId>
			<version>8.9.0</version>
		</dependency>

Where did you see in the documentation I linked to that you have to import:

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

?

In case you did not see it, let me copy/paste this for you:

<project>
  <dependencies>

    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>8.9.0</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.12.3</version>
    </dependency>

  </dependencies>
</project>

But note that you might have some troubles with the spring data dependencies if you are using it, in which case you will need to fix the transitive deps.

Finally you did not tel which elasticsearch version you have?

Elastic version is 8.9.0.
I am not using spring data, so I removed that dependency. Now the dependencies are like below and its still failing with same error:

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>
		<dependency>
			<groupId>co.elastic.clients</groupId>
			<artifactId>elasticsearch-java</artifactId>
			<version>8.9.0</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.12.3</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>

		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>io.projectreactor</groupId>
			<artifactId>reactor-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

I think that the BOM of spring boot declares something.

Run a

mvn dependency:tree

To find out what's wrong. Pretty sure that the low level client does not have the right version. See Maven Repository | Elasticsearch Java API Client [8.9] | Elastic

Also look at this : Installation | Elasticsearch Java API Client [8.9] | Elastic

Hi,

I think I am having the same problem.
The client of 8.8.2 is working fine.
When I switch to 8.9.0 I have this error:

java.lang.NoSuchMethodError: 'void co.elastic.clients.transport.rest_client.RestClientTransport.<init>(org.elasticsearch.client.RestClient, co.elastic.clients.json.JsonpMapper, co.elastic.cl
ients.transport.TransportOptions)'
        at org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations$ElasticsearchTransportConfiguration.restClientTransport(ElasticsearchClientConfigurations.ja
va:90)

Looking at the depedency tree:

[INFO] +- com.<hidden>:compile
[INFO] |  +- co.elastic.clients:elasticsearch-java:jar:8.9.0:compile
[INFO] |  |  +- org.elasticsearch.client:elasticsearch-rest-client:jar:8.9.0:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.16:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.5:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.16:compile
[INFO] |  |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  \- org.eclipse.parsson:parsson:jar:1.0.0:compile
[INFO] |  +- org.apache.maven:maven-artifact:jar:3.8.1:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:3.2.1:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:3.0.7:compile

Can you please help?

UPDATE: After further investigation, I think the problem might be some incompatibility between org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations and the 8.9.0 RestClientTransport.
The exception is:

2023-08-02T11:29:44.733Z <> {index=1286,scope=,engagement=,session=,request=,span=,thread=main} DEBUG: [o.s.b.d.LoggingFailureAnalysisReporter] Application failed to start due to an exceptio
n
java.lang.NoSuchMethodError: 'void co.elastic.clients.transport.rest_client.RestClientTransport.<init>(org.elasticsearch.client.RestClient, co.elastic.clients.json.JsonpMapper, co.elastic.cl
ients.transport.TransportOptions)'
        at org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations$ElasticsearchTransportConfiguration.restClientTransport(ElasticsearchClientConfigurations.ja
va:90)

And digging into the code of ElasticsearchClientConfigurations:

    @Import({JacksonJsonpMapperConfiguration.class, JsonbJsonpMapperConfiguration.class, SimpleJsonpMapperConfiguration.class})
    @ConditionalOnBean({RestClient.class})
    @ConditionalOnMissingBean({ElasticsearchTransport.class})
    static class ElasticsearchTransportConfiguration {
        ElasticsearchTransportConfiguration() {
        }

        @Bean
        RestClientTransport restClientTransport(RestClient restClient, JsonpMapper jsonMapper, ObjectProvider<TransportOptions> transportOptions) {
            return new RestClientTransport(restClient, jsonMapper, (TransportOptions)transportOptions.getIfAvailable());
        }
    }

The 8.8.2 contructor of RestClientTransport is compatible with the spring boot autoconfigurer:

    public RestClientTransport(RestClient restClient, JsonpMapper mapper, @Nullable TransportOptions options) 

Where as in 8.9.0 the contructor of RestClientTransport has a different contructor:

    public RestClientTransport(RestClient restClient, JsonpMapper jsonpMapper, RestClientOptions options)

As a workaround this works:

@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientAutoConfiguration.class )

But I think that the solution should be by fixing the 8.9.x java client.

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