# 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)'

**URL:** https://discuss.elastic.co/t/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/327762
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [March 15, 2023, 2:34pm UTC](https://discuss.elastic.co/t/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/327762 "2023-03-15T14:34:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [March 15, 2023, 2:34pm UTC](https://discuss.elastic.co/t/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/327762/1 "2023-03-15T14:34:31Z")

</div>

Elasticsearch 8 is expecting some class RequestOptions which is present in elasticsearch-rest-client-7.6.2.jar.  
How I can resolve this error done exactly in a way mentioned in [elastic8 docs](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html)

```auto
@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;
}

POM.xml

<jackson.version>2.11.3</jackson.version>

   </properties>
   <dependencies>
       <dependency>
           <groupId>co.elastic.clients</groupId>
           <artifactId>elasticsearch-java</artifactId>
           <version>8.6.2</version>
       </dependency>
       <dependency>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-core</artifactId>
           <version>${jackson.version}</version>
       </dependency>
       <dependency>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-databind</artifactId>
           <version>${jackson.version}</version>
       </dependency>
       <dependency>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-annotations</artifactId>
           <version>${jackson.version}</version>
       </dependency>
<!-- <dependency>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- <version>2.12.3</version>-->
<!-- </dependency>-->
       <dependency>
           <groupId>jakarta.json</groupId>
           <artifactId>jakarta.json-api</artifactId>
           <version>2.0.1</version>
       </dependency>

--------------------
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:

   jar:file:/Users/sureshc1/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar!/org/elasticsearch/client/RequestOptions$Builder.class

-------------
MY analysis
the Class elastic 8 uses RestClient is present in elastic 7 when I search in documentation in elastic8 it is not present.
RequestOPtions is also present in elastic 7 only it is not present in 8 
kindly help here

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 15, 2023, 9:50pm UTC](https://discuss.elastic.co/t/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/327762/2 "2023-03-15T21:50:31Z")

</div>

That's not the same client. The 7.x is the old RestHighLevelClient. The 8.x is a new one which basically does not need that class.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 12, 2023, 9:51pm UTC](https://discuss.elastic.co/t/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/327762/3 "2023-04-12T21:51:05Z")

</div>

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