Skip to content

Commit 305d930

Browse files
authoredAug 30, 2021
Remove org.elasticsearch dependencies from API classes.
Original Pull Request #1913 Closes #1884 Closes #1885
1 parent e688fc7 commit 305d930

File tree

64 files changed

+2120
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2120
-855
lines changed
 

‎src/main/asciidoc/reference/elasticsearch-clients.adoc

+25-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
This chapter illustrates configuration and usage of supported Elasticsearch client implementations.
55

6-
Spring Data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster. 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>>.
6+
Spring Data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster.
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>>.
78

89
[[elasticsearch.clients.transport]]
910
== Transport Client
1011

11-
WARNING: The `TransportClient` is deprecated as of Elasticsearch 7 and will be removed in Elasticsearch 8. (https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html[see the Elasticsearch documentation]). Spring Data Elasticsearch will support the `TransportClient` as long as it is available in the used
12-
Elasticsearch <<elasticsearch.versions,version>> but has deprecated the classes using it since version 4.0.
12+
WARNING: The `TransportClient` is deprecated as of Elasticsearch 7 and will be removed in Elasticsearch 8. (https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html[see the Elasticsearch documentation]).
13+
Spring Data Elasticsearch will support the `TransportClient` as long as it is available in the used Elasticsearch <<elasticsearch.versions,version>> but has deprecated the classes using it since version 4.0.
1314

1415
We strongly recommend to use the <<elasticsearch.clients.rest>> instead of the `TransportClient`.
1516

@@ -46,6 +47,7 @@ IndexRequest request = new IndexRequest("spring-data")
4647
4748
IndexResponse response = client.index(request);
4849
----
50+
4951
<.> The `TransportClient` must be configured with the cluster name.
5052
<.> The host and port to connect the client to.
5153
<.> the RefreshPolicy must be set in the `ElasticsearchTemplate` (override `refreshPolicy()` to not use the default)
@@ -54,8 +56,7 @@ IndexResponse response = client.index(request);
5456
[[elasticsearch.clients.rest]]
5557
== High Level REST Client
5658

57-
The Java High Level REST Client is the default client of Elasticsearch, it provides a straight forward replacement for the `TransportClient` as it accepts and returns
58-
the very same request/response objects and therefore depends on the Elasticsearch core project.
59+
The Java High Level REST Client is the default client of Elasticsearch, it provides a straight forward replacement for the `TransportClient` as it accepts and returns the very same request/response objects and therefore depends on the Elasticsearch core project.
5960
Asynchronous calls are operated upon a client managed thread pool and require a callback to be notified when the request is done.
6061

6162
.High Level REST Client
@@ -93,6 +94,7 @@ IndexRequest request = new IndexRequest("spring-data")
9394
9495
IndexResponse response = highLevelClient.index(request,RequestOptions.DEFAULT);
9596
----
97+
9698
<1> Use the builder to provide cluster addresses, set default `HttpHeaders` or enable SSL.
9799
<2> Create the RestHighLevelClient.
98100
<3> It is also possible to obtain the `lowLevelRest()` client.
@@ -131,6 +133,7 @@ Mono<IndexResponse> response = client.index(request ->
131133
.source(singletonMap("feature", "reactive-client"));
132134
);
133135
----
136+
134137
<.> Use the builder to provide cluster addresses, set default `HttpHeaders` or enable SSL.
135138
====
136139

@@ -162,39 +165,44 @@ ClientConfiguration clientConfiguration = ClientConfiguration.builder()
162165
headers.add("currentTime", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
163166
return headers;
164167
})
165-
.withWebClientConfigurer(webClient -> { <.>
166-
//...
167-
return webClient;
168-
})
169-
.withHttpClientConfigurer(clientBuilder -> { <.>
170-
//...
168+
.withClientConfigurer( <.>
169+
(ReactiveRestClients.WebClientConfigurationCallback) webClient -> {
170+
// ...
171+
return webClient;
172+
})
173+
.withClientConfigurer( <.>
174+
(RestClients.RestClientConfigurationCallback) clientBuilder -> {
175+
// ...
171176
return clientBuilder;
172-
})
177+
})
173178
. // ... other options
174179
.build();
175180
176181
----
182+
177183
<.> Define default headers, if they need to be customized
178184
<.> Use the builder to provide cluster addresses, set default `HttpHeaders` or enable SSL.
179185
<.> Optionally enable SSL.
180186
<.> Optionally set a proxy.
181187
<.> Optionally set a path prefix, mostly used when different clusters a behind some reverse proxy.
182-
<.> Set the connection timeout. Default is 10 sec.
183-
<.> Set the socket timeout. Default is 5 sec.
188+
<.> Set the connection timeout.
189+
Default is 10 sec.
190+
<.> Set the socket timeout.
191+
Default is 5 sec.
184192
<.> Optionally set headers.
185193
<.> Add basic authentication.
186194
<.> 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.
187195
<.> for reactive setup a function configuring the `WebClient`
188196
<.> for non-reactive setup a function configuring the REST client
189197
====
190198

191-
IMPORTANT: Adding a Header supplier as shown in above example allows to inject headers that may change over the time, like authentication JWT tokens. If this is used in the reactive setup, the supplier function *must not* block!
199+
IMPORTANT: Adding a Header supplier as shown in above example allows to inject headers that may change over the time, like authentication JWT tokens.
200+
If this is used in the reactive setup, the supplier function *must not* block!
192201

193202
[[elasticsearch.clients.logging]]
194203
== Client Logging
195204

196-
To see what is actually sent to and received from the server `Request` / `Response` logging on the transport level needs
197-
to be turned on as outlined in the snippet below.
205+
To see what is actually sent to and received from the server `Request` / `Response` logging on the transport level needs to be turned on as outlined in the snippet below.
198206

199207
.Enable transport layer logging
200208
[source,xml]

‎src/main/asciidoc/reference/elasticsearch-migration-guide-4.2-4.3.adoc

+42-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,53 @@
33

44
This section describes breaking changes from version 4.2.x to 4.3.x and how removed features can be replaced by new introduced features.
55

6+
[NOTE]
7+
====
8+
Elasticsearch is working on a new Client that will replace the `RestHighLevelClient` because the `RestHighLevelClient` uses code from Elasticsearch core libraries which are not Apache 2 licensed anymore.
9+
Spring Data Elasticsearch is preparing for this change as well.
10+
This means that internally the implementations for the `*Operations` interfaces need to change - which should be no problem if users program against the interfaces like `ElasticsearchOperations` or `ReactiveElasticsearchOperations`.
11+
If you are using the implementation classes like `ElasticsearchRestTemplate` directly, you will need to adapt to these changes.
12+
13+
Spring Data Elasticsearch also removes or replaces the use of classes from the `org.elasticsearch` packages in it's API classes and methods, only using them in the implementation where the access to Elasticsearch is implemented.
14+
For the user that means, that some enum classes that were used are replaced by enums that live in `org.springframework.data.elasticsearch` with the same values, these are internally mapped onto the Elasticsearch ones.
15+
16+
Places where classes are used that cannot easily be replaced, this usage is marked as deprecated, we are working on replacements.
17+
18+
Check the sections on <<elasticsearch-migration-guide-4.2-4.3.deprecations>> and <<elasticsearch-migration-guide-4.2-4.3.breaking-changes>> for further details.
19+
====
20+
621
[[elasticsearch-migration-guide-4.2-4.3.deprecations]]
722
== Deprecations
823

924
[[elasticsearch-migration-guide-4.2-4.3.breaking-changes]]
1025
== Breaking Changes
1126

27+
=== Removal of `org.elasticsearch` classes from the API.
28+
29+
* In the `org.springframework.data.elasticsearch.annotations.CompletionContext` annotation the property `type()` has changed from `org.elasticsearch.search.suggest.completion.context.ContextMapping.Type` to `org.springframework.data.elasticsearch.annotations.CompletionContext.ContextMappingType`, the available enum values are the same.
30+
* In the `org.springframework.data.elasticsearch.annotations.Document` annotation the `versionType()` property has changed to `org.springframework.data.elasticsearch.annotations.Document.VersionType`, the available enum values are the same.
31+
* In the `org.springframework.data.elasticsearch.core.query.Query` interface the `searchType()` property has changed to `org.springframework.data.elasticsearch.core.query.Query.SearchType`, the available enum values are the same.
32+
* In the `org.springframework.data.elasticsearch.core.query.Query` interface the return value of `timeout()` was changed to `java.time.Duration`.
33+
1234
=== Handling of field and sourceFilter properties of Query
1335

14-
Up to version 4.2 the `fields` property of a `Query` was interpreted and added to the include list of the `sourceFilter`. This was not correct, as these are different things for Elasticsearch. This has been corrected. As a consequence code might not work anymore that relies on using `fields` to specify which fields should be returned from the document's `_source' and should be changed to use the `sourceFilter`.
36+
Up to version 4.2 the `fields` property of a `Query` was interpreted and added to the include list of the `sourceFilter`.
37+
This was not correct, as these are different things for Elasticsearch.
38+
This has been corrected.
39+
As a consequence code might not work anymore that relies on using `fields` to specify which fields should be returned from the document's `_source' and should be changed to use the `sourceFilter`.
40+
41+
=== search_type default value
42+
43+
The default value for the `search_type` in Elasticsearch is `query_then_fetch`.
44+
This now is also set as default value in the `Query` implementations, it was previously set to `dfs_query_then_fetch`.
45+
46+
=== BulkOptions changes
47+
48+
Some properties of the `org.springframework.data.elasticsearch.core.query.BulkOptions` class have changed their type:
49+
50+
* the type of the `timeout` property has been changed to `java.time.Duration`.
51+
* the type of the`refreshPolicy` property has been changed to `org.springframework.data.elasticsearch.core.RefreshPolicy`.
52+
53+
=== IndicesOptions change
54+
55+
Spring Data Elasticsearch now uses `org.springframework.data.elasticsearch.core.query.IndicesOptions` instead of `org.elasticsearch.action.support.IndicesOptions`.

0 commit comments

Comments
 (0)
Please sign in to comment.