Skip to content

Commit 305d930

Browse files
authored
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

Diff for: 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]

Diff for: 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`.

Diff for: src/main/java/org/springframework/data/elasticsearch/annotations/CompletionContext.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.elasticsearch.annotations;
217

318
import java.lang.annotation.Documented;
@@ -7,12 +22,11 @@
722
import java.lang.annotation.RetentionPolicy;
823
import java.lang.annotation.Target;
924

10-
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
11-
1225
/**
1326
* Based on reference doc - https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html
1427
*
1528
* @author Robert Gruendler
29+
* @author Peter-Josef Meisch
1630
*/
1731
@Retention(RetentionPolicy.RUNTIME)
1832
@Target(ElementType.FIELD)
@@ -22,9 +36,16 @@
2236

2337
String name();
2438

25-
ContextMapping.Type type();
39+
ContextMappingType type();
2640

2741
String precision() default "";
2842

2943
String path() default "";
44+
45+
/**
46+
* @since 4.3
47+
*/
48+
enum ContextMappingType {
49+
CATEGORY, GEO
50+
}
3051
}

Diff for: src/main/java/org/springframework/data/elasticsearch/annotations/Document.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.lang.annotation.RetentionPolicy;
2222
import java.lang.annotation.Target;
2323

24-
import org.elasticsearch.index.VersionType;
2524
import org.springframework.data.annotation.Persistent;
2625

2726
/**
@@ -116,9 +115,15 @@
116115

117116
/**
118117
* Controls how Elasticsearch dynamically adds fields to the document.
119-
*
118+
*
120119
* @since 4.3
121120
*/
122121
Dynamic dynamic() default Dynamic.INHERIT;
123122

123+
/**
124+
* @since 4.3
125+
*/
126+
enum VersionType {
127+
INTERNAL, EXTERNAL, EXTERNAL_GTE
128+
}
124129
}

Diff for: src/main/java/org/springframework/data/elasticsearch/client/ClientConfiguration.java

+46-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.net.ssl.SSLContext;
2828

2929
import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback;
30+
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
3031
import org.springframework.http.HttpHeaders;
3132
import org.springframework.lang.Nullable;
3233
import org.springframework.web.reactive.function.client.WebClient;
@@ -120,16 +121,16 @@ static ClientConfiguration create(InetSocketAddress socketAddress) {
120121
boolean useSsl();
121122

122123
/**
123-
* Returns the {@link SSLContext} to use. Can be {@link Optional#empty()} if unconfigured.
124+
* Returns the {@link SSLContext} to use. Can be {@link Optional#empty()} if not configured.
124125
*
125-
* @return the {@link SSLContext} to use. Can be {@link Optional#empty()} if unconfigured.
126+
* @return the {@link SSLContext} to use. Can be {@link Optional#empty()} if not configured.
126127
*/
127128
Optional<SSLContext> getSslContext();
128129

129130
/**
130-
* Returns the {@link HostnameVerifier} to use. Can be {@link Optional#empty()} if unconfigured.
131+
* Returns the {@link HostnameVerifier} to use. Can be {@link Optional#empty()} if not configured.
131132
*
132-
* @return the {@link HostnameVerifier} to use. Can be {@link Optional#empty()} if unconfigured.
133+
* @return the {@link HostnameVerifier} to use. Can be {@link Optional#empty()} if not configured.
133134
*/
134135
Optional<HostnameVerifier> getHostNameVerifier();
135136

@@ -152,7 +153,7 @@ static ClientConfiguration create(InetSocketAddress socketAddress) {
152153

153154
/**
154155
* Returns the path prefix that should be prepended to HTTP(s) requests for Elasticsearch behind a proxy.
155-
*
156+
*
156157
* @return the path prefix.
157158
* @since 4.0
158159
*/
@@ -161,7 +162,7 @@ static ClientConfiguration create(InetSocketAddress socketAddress) {
161162

162163
/**
163164
* returns an optionally set proxy in the form host:port
164-
*
165+
*
165166
* @return the optional proxy
166167
* @since 4.0
167168
*/
@@ -173,11 +174,19 @@ static ClientConfiguration create(InetSocketAddress socketAddress) {
173174
Function<WebClient, WebClient> getWebClientConfigurer();
174175

175176
/**
176-
* @return the client configuration callback.
177+
* @return the Rest Client configuration callback.
177178
* @since 4.2
179+
* @deprecated since 4.3 use {@link #getClientConfigurer()}
178180
*/
181+
@Deprecated
179182
HttpClientConfigCallback getHttpClientConfigurer();
180183

184+
/**
185+
* @return the client configuration callback
186+
* @since 4.3
187+
*/
188+
<T> ClientConfigurationCallback<T> getClientConfigurer();
189+
181190
/**
182191
* @return the supplier for custom headers.
183192
*/
@@ -274,7 +283,7 @@ interface TerminalClientConfigurationBuilder {
274283
TerminalClientConfigurationBuilder withDefaultHeaders(HttpHeaders defaultHeaders);
275284

276285
/**
277-
* Configure the {@literal milliseconds} for the connect timeout.
286+
* Configure the {@literal milliseconds} for the connect-timeout.
278287
*
279288
* @param millis the timeout to use.
280289
* @return the {@link TerminalClientConfigurationBuilder}
@@ -327,7 +336,7 @@ default TerminalClientConfigurationBuilder withSocketTimeout(long millis) {
327336

328337
/**
329338
* Configure the path prefix that will be prepended to any HTTP(s) requests
330-
*
339+
*
331340
* @param pathPrefix the pathPrefix.
332341
* @return the {@link TerminalClientConfigurationBuilder}
333342
* @since 4.0
@@ -342,21 +351,36 @@ default TerminalClientConfigurationBuilder withSocketTimeout(long millis) {
342351

343352
/**
344353
* set customization hook in case of a reactive configuration
345-
*
354+
*
346355
* @param webClientConfigurer function to configure the WebClient
347356
* @return the {@link TerminalClientConfigurationBuilder}.
357+
* @deprecated since 4.3, use {@link #withClientConfigurer(ClientConfigurationCallback)} with
358+
* {@link ReactiveRestClients.WebClientConfigurationCallback}
348359
*/
360+
@Deprecated
349361
TerminalClientConfigurationBuilder withWebClientConfigurer(Function<WebClient, WebClient> webClientConfigurer);
350362

351363
/**
352364
* Register a {HttpClientConfigCallback} to configure the non-reactive REST client.
353-
*
365+
*
354366
* @param httpClientConfigurer configuration callback, must not be null.
355367
* @return the {@link TerminalClientConfigurationBuilder}.
356368
* @since 4.2
369+
* @deprecated since 4.3, use {@link #withClientConfigurer(ClientConfigurationCallback)} with
370+
* {@link RestClients.RestClientConfigurationCallback}
357371
*/
372+
@Deprecated
358373
TerminalClientConfigurationBuilder withHttpClientConfigurer(HttpClientConfigCallback httpClientConfigurer);
359374

375+
/**
376+
* Register a {@link ClientConfigurationCallback} to configure the client.
377+
*
378+
* @param clientConfigurer configuration callback, must not be {@literal null}.
379+
* @return the {@link TerminalClientConfigurationBuilder}.
380+
* @since 4.3
381+
*/
382+
TerminalClientConfigurationBuilder withClientConfigurer(ClientConfigurationCallback<?> clientConfigurer);
383+
360384
/**
361385
* set a supplier for custom headers. This is invoked for every HTTP request to Elasticsearch to retrieve headers
362386
* that should be sent with the request. A common use case is passing in authentication headers that may change.
@@ -377,4 +401,15 @@ default TerminalClientConfigurationBuilder withSocketTimeout(long millis) {
377401
*/
378402
ClientConfiguration build();
379403
}
404+
405+
/**
406+
* Callback to be executed to configure a client.
407+
*
408+
* @param <T> the type of the client configuration class.
409+
* @since 4.3
410+
*/
411+
@FunctionalInterface
412+
interface ClientConfigurationCallback<T> {
413+
T configure(T clientConfigurer);
414+
}
380415
}

0 commit comments

Comments
 (0)