Search code examples
javakotlinelasticsearchelasticsearch-java-api

How to disable compatibility header in Elasticsearch Java API Client?


I'm trying to config my application to interaction with Elastcisearch server v7.7 using Java API Client v7.16.3. But when I try to index new document, I get the following error:

{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=7] is not supported","status":406}

As far as I understand, the reason is the compatibility Content-type header which value contains compatible-with=7. Elasticsearch v7.7 doesn't support this content-type (while Elasticsearch v7.15 works fine with it). Here is my configuration:

    fun configElasticsearchRestClient(
        host: String,
        username: String,
        password: String
    ): ElasticsearchClient {
        val elasticsearchRestClient =  RestClient.builder(HttpHost.create(host))
            .build()
        val transport: ElasticsearchTransport = RestClientTransport(
            elasticsearchRestClient,
            JacksonJsonpMapper()
        )
        return ElasticsearchClient(transport)
    }

And here is indexing method:

    fun index(document: SomeDocument) {
        val indexRequest = IndexRequest.Builder<ObjectNode>()
            .index("some-index")
            .document(document)
            .id(document.getId())
            .version(document.getVersion())
            .versionType(External)
            .build()

        elasticsearchClient.index(indexRequest)
    }

Is it possible do disable compatibility headers for Java API Client? Or is there any another way to use Java API Client for Elasticsearch server v7.7?


Solution

  • You should always use a client library version that is compatible with the server version. In this case you're using a recent version of the client library (i.e. 7.16.3) with an older version of the server (i.e. 7.7), you're not supposed to do that, or you should expect some backward incompatibility issues:

    The client must have the same major version (e.g. 2.x, or 5.x) as the nodes in the cluster. Clients may connect to clusters which have a different minor version (e.g. 2.3.x) but it is possible that new functionality may not be supported. Ideally, the client should have the same version as the cluster.

    If you use the Java client 7.7 instead, you won't have any problems.

    Also, as you can see from the latest Java Client source code, the compatible-with value is hardcoded into the HTTP header value. If a header is found to not have that compatibility check, it is modified automatically to include it, so there's no way to turn it off.