# Java api client 7.x with Elasticsearch server 8.x

**URL:** <https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 2, 2024, 7:51am UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369 "2024-02-02T07:51:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SElasticsearch](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@SElasticsearch](https://discuss.elastic.co/u/SElasticsearch)\
**Post date:** [February 2, 2024, 7:51am UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369/1 "2024-02-02T07:51:54Z")

</div>

We have a scenario where our application needs to connect with both 7.x and 8.x Elasticsearch server. Using Java API client 7.17.16 and it works with Elasticsearch server 7.x. Used (HttpHeaders.CONTENT\_TYPE, "application/json") as default header.

However, when using the same headers with Java API client 7.17.16 against Elasticsearch Server 8.x. , it throws an error complaining about headers.

Please let me know what headers I can use against both the servers.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [February 2, 2024, 10:25am UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369/2 "2024-02-02T10:25:57Z")

</div>

Hi @SElasticsearch,

Welcome! Can I confirm which Java client you are using? The Java API client, Java low level client or the deprecated Java REST client? If you could also share the full error message that would be helpful.

Looking at the documentation the [Java API client states it is forward compatible with greater than or equal minor versions](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/introduction.html#_elasticsearch_server_compatibility_policy). If you're using the Java REST client you need to use compatibility mode with v8.x as outlined [here](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-compatibility.html).

Let us know!.

---

<div class="post-metadata">

**Author:** ![SElasticsearch](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@SElasticsearch](https://discuss.elastic.co/u/SElasticsearch)\
**Post date:** [February 2, 2024, 8:02pm UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369/3 "2024-02-02T20:02:22Z")

</div>

> [@carly.richmond](#):
>
> Java API clien

I am using Java Api client : 7.17.16. While trying to connect to ElasticServer version 8.10.3  
Error message : reason":"A compatible version is required on both Content-Type and Accept headers if either one has requested a compatible version and the compatible versions must match. Accept=application/vnd.elasticsearch+json; compatible-with=7, Content-Type=application/json

What should be the header that will work with both Elasticsearch 7x and Elasticsearch 8x servers.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [February 5, 2024, 11:35am UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369/4 "2024-02-05T11:35:37Z")

</div>

Hi @SElasticsearch,

The headers you need are covered [here in the documentation under REST compatibility](https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-api-compatibility.html#request-rest-api-compatibility).

Hope that helps!

---

<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:** [March 4, 2024, 11:36am UTC](https://discuss.elastic.co/t/java-api-client-7-x-with-elasticsearch-server-8-x/352369/5 "2024-03-04T11:36:35Z")

</div>

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