Skip to content

Commit 453460f

Browse files
committed
Update compatibility headers documentation
1 parent cf380e2 commit 453460f

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

Diff for: src/main/asciidoc/reference/elasticsearch-clients.adoc

+18-13
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,28 @@ If this is used in the reactive setup, the supplier function *must not* block!
154154
=== Elasticsearch 7 compatibility headers
155155

156156
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
157-
https://www.elastic.co/guide/en/elasticsearch/reference/8.0/rest-api-compatibility.html[see Elasticserach documentation].
158-
This should be done using a header supplier like shown above:
157+
https://www.elastic.co/guide/en/elasticsearch/reference/8.0/rest-api-compatibility.html[see Elasticsearch
158+
documentation].
159+
160+
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:
159161

160162
====
161163
[source,java]
162164
----
163-
ClientConfigurationBuilder configurationBuilder = new ClientConfigurationBuilder();
164-
configurationBuilder //
165-
// ...
166-
.withHeaders(() -> {
167-
HttpHeaders defaultCompatibilityHeaders = new HttpHeaders();
168-
defaultCompatibilityHeaders.add("Accept",
169-
"application/vnd.elasticsearch+json;compatible-with=7");
170-
defaultCompatibilityHeaders.add("Content-Type",
171-
"application/vnd.elasticsearch+json;compatible-with=7");
172-
return defaultCompatibilityHeaders;
173-
});
165+
166+
HttpHeaders compatibilityHeaders = new HttpHeaders();
167+
compatibilityHeaders.add("Accept", "application/vnd.elasticsearch+json;compatible-with=7");
168+
compatibilityHeaders.add("Content-Type", "application/vnd.elasticsearch+json;"
169+
+ "compatible-with=7");
170+
171+
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
172+
.connectedTo("localhost:9200")
173+
.withProxy("localhost:8080")
174+
.withBasicAuth("elastic","hcraescitsale")
175+
.withDefaultHeaders(compatibilityHeaders) // this variant for imperative code
176+
.withHeaders(() -> compatibilityHeaders) // this variant for reactive code
177+
.build();
178+
174179
----
175180
====
176181

0 commit comments

Comments
 (0)