Elasticsearch 8 Client is giving error The following method did not exist: ‘org.elasticsearch.client.RequestOptions$Builder org.elasticsearch.client.RequestOptions$Builder.removeHeader(java.lang.String)’

I have copied exactly the same steps as the documentation elastic8 docs

@Bean
public ElasticsearchClient getElasticSearchClient(){
  RestClient restClient = RestClient.builder(
          new HttpHost("", 9200)).build();

// Create the transport with a Jackson mapper
  ElasticsearchTransport transport = new RestClientTransport(
          restClient, new JacksonJsonpMapper());

// And create the API client
  ElasticsearchClient client = new ElasticsearchClient(transport);
  
  return client;
}

and I'm receiving this error

Error it gives

An attempt was made to call a method that does not exist. The attempt was made from the following location:

   co.elastic.clients.transport.rest_client.RestClientOptions.addBuiltinHeaders(RestClientOptions.java:170)

The following method did not exist:

   'org.elasticsearch.client.RequestOptions$Builder org.elasticsearch.client.RequestOptions$Builder.removeHeader(java.lang.String)'

The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:

Saw the library of rest_client that was causing the issue and it's 7.2.
my pom is the following


  <parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <groupId>org.springframework.boot</groupId>
    <version>2.6.2</version>
  </parent>

  <properties>
    <apache.beam.version>2.39.0</apache.beam.version>
    <java.version>11</java.version>
    <elasticsearch-java.version>7.17.0</elasticsearch-java.version>
    <jakarta-json-api.version>2.0.1</jakarta-json-api.version>

    <!-- testing... -->

  </properties>

  <version>latest-SNAPSHOT</version>
  
  <dependencies>
    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>${elasticsearch-java.version}</version>
    </dependency>

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

Welcome! Have a look at the dependency tree.

It will probably show you that you are not using the right version of the low level client.

Looks like it's the apache beam who's downloading the dependency of

- org.apache.beam:beam-sdks-java-io-elasticsearch:jar:2.39.0:compile
[INFO] |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.5:compile
[INFO] |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.15:compile
[INFO] |  \- org.elasticsearch.client:elasticsearch-rest-client:jar:7.15.2:compile

I made the exclusion from apache beam

  <dependency>
      <artifactId>beam-sdks-java-io-elasticsearch</artifactId>
      <groupId>org.apache.beam</groupId>
      <version>${apache.beam.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.elasticsearch.client</groupId>
          <artifactId>elasticsearch-rest-client</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

my dependency tree looks like

 +- co.elastic.clients:elasticsearch-java:jar:8.8.0:compile
[INFO] |  +- org.elasticsearch.client:elasticsearch-rest-client:jar:7.15.2:compile
[INFO] |  \- org.eclipse.parsson:parsson:jar:1.0.0:compile

and still receives the same error
@dadoonet

You need to use 7.17.10 or 7.17.11 for both clients.

does that mean the 8.8 doesn't work or what? I'm not sure I get your answer

In your Pom, you set 7.17.0 as the version. So I guessed you are using a 7.17.0 version. Am I wrong?

What is your Elasticsearch server version?

my bad. I switched my pom to using the 8.8 version. copied the previous pom

the ES version I'm using is 8.
the lib version is 8.8
the rest-client downloaded via the lib is 7.5
the issue is still there

the rest-client downloaded via the lib is 7.5

No. It's not the lib. It's probably a problem with the spring parent.

So you should "force" the low level client:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-client</artifactId>
    <version>8.8.0</version>
</dependency>
1 Like

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