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

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.

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. If you're using the Java REST client you need to use compatibility mode with v8.x as outlined here.

Let us know!.

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.

Hi @SElasticsearch,

The headers you need are covered here in the documentation under REST compatibility.

Hope that helps!