Update compatibility headers documentation

This commit is contained in:
Peter-Josef Meisch 2022-02-19 13:45:21 +01:00
parent cf380e289d
commit 453460fab3
No known key found for this signature in database
GPG Key ID: DE108246970C7708

View File

@ -154,23 +154,28 @@ If this is used in the reactive setup, the supplier function *must not* block!
=== Elasticsearch 7 compatibility headers === Elasticsearch 7 compatibility headers
When using Spring Data Elasticsearch 4 - which uses the Elasticsearch 7 client libraries - and accessing an Elasticsearch cluster that is running on version 8, it is necessary to set the compatibility headers When using Spring Data Elasticsearch 4 - which uses the Elasticsearch 7 client libraries - and accessing an Elasticsearch cluster that is running on version 8, it is necessary to set the compatibility headers
https://www.elastic.co/guide/en/elasticsearch/reference/8.0/rest-api-compatibility.html[see Elasticserach documentation]. https://www.elastic.co/guide/en/elasticsearch/reference/8.0/rest-api-compatibility.html[see Elasticsearch
This should be done using a header supplier like shown above: documentation].
For the imperative client this must be done by setting the default headers, for the reactive code this must be done using a header supplier:
==== ====
[source,java] [source,java]
---- ----
ClientConfigurationBuilder configurationBuilder = new ClientConfigurationBuilder();
configurationBuilder // HttpHeaders compatibilityHeaders = new HttpHeaders();
// ... compatibilityHeaders.add("Accept", "application/vnd.elasticsearch+json;compatible-with=7");
.withHeaders(() -> { compatibilityHeaders.add("Content-Type", "application/vnd.elasticsearch+json;"
HttpHeaders defaultCompatibilityHeaders = new HttpHeaders(); + "compatible-with=7");
defaultCompatibilityHeaders.add("Accept",
"application/vnd.elasticsearch+json;compatible-with=7"); ClientConfiguration clientConfiguration = ClientConfiguration.builder()
defaultCompatibilityHeaders.add("Content-Type", .connectedTo("localhost:9200")
"application/vnd.elasticsearch+json;compatible-with=7"); .withProxy("localhost:8080")
return defaultCompatibilityHeaders; .withBasicAuth("elastic","hcraescitsale")
}); .withDefaultHeaders(compatibilityHeaders) // this variant for imperative code
.withHeaders(() -> compatibilityHeaders) // this variant for reactive code
.build();
---- ----
==== ====