You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for upcoming versions of Elasticsearch is being tracked and general compatibility should be given assuming the usage of the <<elasticsearch.clients.rest,high-level REST client>>.
52
+
Support for upcoming versions of Elasticsearch is being tracked and general compatibility should be given assuming
53
+
the usage of the <<elasticsearch.operations,ElasticsearchOperations interface>>.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/elasticsearch-clients.adoc
+104-18
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,104 @@ This chapter illustrates configuration and usage of supported Elasticsearch clie
6
6
Spring Data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster.
7
7
Although the Elasticsearch Client can be used to work with the cluster, applications using Spring Data Elasticsearch normally use the higher level abstractions of <<elasticsearch.operations>> and <<elasticsearch.repositories>>.
8
8
9
-
[[elasticsearch.clients.rest]]
10
-
== High Level REST Client
9
+
[[elasticsearch.clients.restclient]]
10
+
== Imperative Rest Client
11
11
12
-
The Java High Level REST Client is the default client of Elasticsearch, it is configured like shown:
12
+
To use the imperative (non-reactive) client, a configuration bean must be configured like this:
The `ReactiveElasticsearchClient` is a non official driver based on `WebClient`.
147
+
The `org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient` is a non official driver based on `WebClient`.
59
148
It uses the request/response objects provided by the Elasticsearch core project.
60
149
Calls are directly operated on the reactive stack, **not** wrapping async (thread pool bound) responses into reactive types.
61
150
62
-
.Reactive REST Client
151
+
This was the first reactive implementation Spring Data Elasticsearch provided, but now is deprecated in favour of the `org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient`
152
+
which uses the functionality offered by the new Elasticsearch client libraries.
<.> A `Supplier<Header>` function can be specified which is called every time before a request is sent to Elasticsearch - here, as an example, the current time is written in a header.
147
-
<.> for reactive setup a function configuring the `WebClient`
148
-
<.> for non-reactive setup a function configuring the REST client
234
+
<.> a function configuring the low level REST client (the same for the imperative and reactive stack)
149
235
====
150
236
151
237
IMPORTANT: Adding a Header supplier as shown in above example allows to inject headers that may change over the time, like authentication JWT tokens.
152
238
If this is used in the reactive setup, the supplier function *must not* block!
153
239
154
240
=== Elasticsearch 7 compatibility headers
155
241
156
-
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
242
+
When using the deprecated `RestHighLevelClient` and accessing an Elasticsearch cluster that is running on version 8, it is necessary to set the compatibility headers
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/elasticsearch-join-types.adoc
+11-5
Original file line number
Diff line number
Diff line change
@@ -211,19 +211,25 @@ void init() {
211
211
212
212
== Retrieving data
213
213
214
-
Currently native search queries must be used to query the data, so there is no support from standard repository methods. <<repositories.custom-implementations>> can be used instead.
214
+
Currently native queries must be used to query the data, so there is no support from standard repository methods. <<repositories.custom-implementations>> can be used instead.
215
215
216
216
The following code shows as an example how to retrieve all entries that have a _vote_ (which must be _answers_, because only answers can have a vote) using an `ElasticsearchOperations` instance:
217
217
218
218
====
219
219
[source,java]
220
220
----
221
221
SearchHits<Statement> hasVotes() {
222
-
NativeSearchQuery query = new NativeSearchQueryBuilder()
To configure Spring Data Elasticsearch to use the new client, it is necessary to create a configuration bean that
96
50
derives from `org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration`:
@@ -118,7 +72,7 @@ With this configuration, the following beans will be available in the Spring app
118
72
* an `ElasticsearchClient` bean, this is the new client that uses the `RestClient`
119
73
* an `ElasticsearchOperations` bean, available with the bean names _elasticsearchOperations_ and _elasticsearchTemplate_, this uses the `ElasticsearchClient`
120
74
121
-
===== Reactive style
75
+
=== Reactive style configuration
122
76
123
77
To use the new client in a reactive environment the only difference is the class from which to derive the configuration:
124
78
@@ -143,3 +97,29 @@ With this configuration, the following beans will be available in the Spring app
143
97
* a `RestClient` bean, that is the configured low level `RestClient` that is used by the Elasticsearch client
144
98
* an `ReactiveElasticsearchClient` bean, this is the new reactive client that uses the `RestClient`
145
99
* an `ReactiveElasticsearchOperations` bean, available with the bean names _reactiveElasticsearchOperations_ and _reactiveElasticsearchTemplate_, this uses the `ReactiveElasticsearchClient`
0 commit comments