Skip to content

Commit f9ebd0d

Browse files
committed
Migrate from RestClient to new Rest5Client
Closes gh-46061
1 parent c41e72a commit f9ebd0d

File tree

21 files changed

+361
-327
lines changed

21 files changed

+361
-327
lines changed

core/spring-boot-testcontainers/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ dependencies {
3636
dockerTestImplementation("com.redis:testcontainers-redis")
3737
dockerTestImplementation("org.assertj:assertj-core")
3838
dockerTestImplementation("org.awaitility:awaitility")
39-
dockerTestImplementation("org.elasticsearch.client:elasticsearch-rest-client")
4039
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
4140
dockerTestImplementation("org.junit.platform:junit-platform-launcher")
4241
dockerTestImplementation("org.mockito:mockito-core")

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/data/nosql.adoc

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ Spring Boot provides a dedicated starter, `spring-boot-starter-data-elasticsearc
314314
[[data.nosql.elasticsearch.connecting-using-rest]]
315315
=== Connecting to Elasticsearch Using REST clients
316316

317-
Elasticsearch ships two different REST clients that you can use to query a cluster: the https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low.html[low-level client] from the `org.elasticsearch.client:elasticsearch-rest-client` module and the https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html[Java API client] from the `co.elastic.clients:elasticsearch-java` module.
317+
Elasticsearch ships two different REST clients that you can use to query a cluster: the https://www.elastic.co/docs/reference/elasticsearch/clients/java/transport/rest5-client/[low-level client] and the https://www.elastic.co/docs/reference/elasticsearch/clients/java[Java API client].
318+
Both clients are provided by the `co.elastic.clients:elasticsearch-java` module.
318319
Additionally, Spring Boot provides support for a reactive client from the `org.springframework.data:spring-data-elasticsearch` module.
319320
By default, the clients will target `http://localhost:9200`.
320321
You can use `spring.elasticsearch.*` properties to further tune how the clients are configured, as shown in the following example:
@@ -332,16 +333,16 @@ spring:
332333

333334

334335
[[data.nosql.elasticsearch.connecting-using-rest.restclient]]
335-
==== Connecting to Elasticsearch Using RestClient
336+
==== Connecting to Elasticsearch Using Rest5Client
336337

337-
If you have `elasticsearch-rest-client` on the classpath, Spring Boot will auto-configure and register a javadoc:org.springframework.web.client.RestClient[] bean.
338-
In addition to the properties described previously, to fine-tune the javadoc:org.springframework.web.client.RestClient[] you can register an arbitrary number of beans that implement javadoc:org.springframework.boot.elasticsearch.autoconfigure.RestClientBuilderCustomizer[] for more advanced customizations.
339-
To take full control over the clients' configuration, define a javadoc:org.elasticsearch.client.RestClientBuilder[] bean.
338+
If you have `co.elastic.clients:elasticsearch-java` on the classpath, Spring Boot will auto-configure and register a javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[] bean.
339+
In addition to the properties described previously, to fine-tune the javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[] you can register an arbitrary number of beans that implement javadoc:org.springframework.boot.elasticsearch.autoconfigure.Rest5ClientBuilderCustomizer[] for more advanced customizations.
340+
To take full control over the client's configuration, define a javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5ClientBuilder[] bean.
340341

341342

342343

343-
Additionally, if `elasticsearch-rest-client-sniffer` is on the classpath, a javadoc:org.elasticsearch.client.sniff.Sniffer[] is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the javadoc:org.springframework.web.client.RestClient[] bean.
344-
You can further tune how javadoc:org.elasticsearch.client.sniff.Sniffer[] is configured, as shown in the following example:
344+
Additionally, a javadoc:co.elastic.clients.transport.rest5_client.low_level.sniffer.Sniffer[] is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[] bean.
345+
You can further tune how javadoc:co.elastic.clients.transport.rest5_client.low_level.sniffer.Sniffer[] is configured, as shown in the following example:
345346

346347
[configprops,yaml]
347348
----
@@ -360,9 +361,9 @@ spring:
360361

361362
If you have `co.elastic.clients:elasticsearch-java` on the classpath, Spring Boot will auto-configure and register an javadoc:co.elastic.clients.elasticsearch.ElasticsearchClient[] bean.
362363

363-
The javadoc:co.elastic.clients.elasticsearch.ElasticsearchClient[] uses a transport that depends upon the previously described javadoc:org.springframework.web.client.RestClient[].
364+
The javadoc:co.elastic.clients.elasticsearch.ElasticsearchClient[] uses a transport that depends upon the previously described javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[].
364365
Therefore, the properties described previously can be used to configure the javadoc:co.elastic.clients.elasticsearch.ElasticsearchClient[].
365-
Furthermore, you can define a javadoc:co.elastic.clients.transport.rest_client.RestClientOptions[] bean to take further control of the behavior of the transport.
366+
Furthermore, you can define a javadoc:co.elastic.clients.transport.rest5_client.Rest5ClientOptions[] bean to take further control of the behavior of the transport.
366367

367368

368369

@@ -372,9 +373,9 @@ Furthermore, you can define a javadoc:co.elastic.clients.transport.rest_client.R
372373
{url-spring-data-elasticsearch-site}[Spring Data Elasticsearch] ships javadoc:org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient[] for querying Elasticsearch instances in a reactive fashion.
373374
If you have Spring Data Elasticsearch and Reactor on the classpath, Spring Boot will auto-configure and register a javadoc:org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient[].
374375

375-
The javadoc:org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient[] uses a transport that depends upon the previously described javadoc:org.springframework.web.client.RestClient[].
376+
The javadoc:org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient[] uses a transport that depends upon the previously described javadoc:co.elastic.clients.transport.rest5_client.low_level.Rest5Client[].
376377
Therefore, the properties described previously can be used to configure the javadoc:org.springframework.data.elasticsearch.client.elc.ReactiveElasticsearchClient[].
377-
Furthermore, you can define a javadoc:co.elastic.clients.transport.rest_client.RestClientOptions[] bean to take further control of the behavior of the transport.
378+
Furthermore, you can define a javadoc:co.elastic.clients.transport.rest5_client.Rest5ClientOptions[] bean to take further control of the behavior of the transport.
378379

379380

380381

module/spring-boot-data-elasticsearch/src/test/java/org/springframework/boot/data/elasticsearch/health/ElasticsearchReactiveHealthIndicatorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import java.util.Map;
2121

2222
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
23-
import co.elastic.clients.transport.rest_client.RestClientTransport;
23+
import co.elastic.clients.transport.rest5_client.Rest5ClientTransport;
24+
import co.elastic.clients.transport.rest5_client.low_level.ResponseException;
25+
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
2426
import okhttp3.mockwebserver.MockResponse;
2527
import okhttp3.mockwebserver.MockWebServer;
26-
import org.apache.http.HttpHost;
27-
import org.elasticsearch.client.ResponseException;
28-
import org.elasticsearch.client.RestClient;
28+
import org.apache.hc.core5.http.HttpHost;
2929
import org.junit.jupiter.api.AfterEach;
3030
import org.junit.jupiter.api.BeforeEach;
3131
import org.junit.jupiter.api.Test;
@@ -59,8 +59,8 @@ class ElasticsearchReactiveHealthIndicatorTests {
5959
void setup() throws Exception {
6060
this.server = new MockWebServer();
6161
this.server.start();
62-
ReactiveElasticsearchClient client = new ReactiveElasticsearchClient(new RestClientTransport(
63-
RestClient.builder(HttpHost.create(this.server.getHostName() + ":" + this.server.getPort())).build(),
62+
ReactiveElasticsearchClient client = new ReactiveElasticsearchClient(new Rest5ClientTransport(
63+
Rest5Client.builder(HttpHost.create(this.server.getHostName() + ":" + this.server.getPort())).build(),
6464
new JacksonJsonpMapper()));
6565
this.healthIndicator = new ElasticsearchReactiveHealthIndicator(client);
6666
}

module/spring-boot-elasticsearch/build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,15 @@ description = "Spring Boot Elasticsearch"
2727

2828
dependencies {
2929
api(project(":core:spring-boot"))
30-
api("org.elasticsearch.client:elasticsearch-rest-client")
30+
api("co.elastic.clients:elasticsearch-java")
3131

3232
optional(project(":core:spring-boot-autoconfigure"))
3333
optional(project(":core:spring-boot-docker-compose"))
3434
optional(project(":core:spring-boot-testcontainers"))
3535
optional(project(":module:spring-boot-health"))
3636
optional(project(":module:spring-boot-jsonb"))
3737
optional(project(":module:spring-boot-reactor"))
38-
optional("co.elastic.clients:elasticsearch-java") {
39-
exclude group: "commons-logging", module: "commons-logging"
40-
}
41-
optional("org.elasticsearch.client:elasticsearch-rest-client-sniffer") {
42-
exclude group: "commons-logging", module: "commons-logging"
43-
}
38+
4439
optional("com.fasterxml.jackson.core:jackson-databind")
4540
optional("jakarta.json.bind:jakarta.json.bind-api")
4641
optional("org.springframework.data:spring-data-elasticsearch") {

module/spring-boot-elasticsearch/src/dockerTest/java/org/springframework/boot/elasticsearch/autoconfigure/ElasticsearchRestClientAutoConfigurationIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
import java.io.InputStream;
2020

21+
import co.elastic.clients.transport.rest5_client.low_level.Request;
22+
import co.elastic.clients.transport.rest5_client.low_level.Response;
23+
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
2124
import com.fasterxml.jackson.databind.JsonNode;
2225
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import org.elasticsearch.client.Request;
24-
import org.elasticsearch.client.Response;
25-
import org.elasticsearch.client.RestClient;
2626
import org.junit.jupiter.api.Test;
2727
import org.testcontainers.elasticsearch.ElasticsearchContainer;
2828
import org.testcontainers.junit.jupiter.Container;
@@ -57,7 +57,7 @@ void restClientCanQueryElasticsearchNode() {
5757
.withPropertyValues("spring.elasticsearch.uris=" + elasticsearch.getHttpHostAddress(),
5858
"spring.elasticsearch.connection-timeout=120s", "spring.elasticsearch.socket-timeout=120s")
5959
.run((context) -> {
60-
RestClient client = context.getBean(RestClient.class);
60+
Rest5Client client = context.getBean(Rest5Client.class);
6161
Request index = new Request("PUT", "/test/_doc/2");
6262
index.setJsonEntity("{" + " \"a\": \"alpha\"," + " \"b\": \"bravo\"" + "}");
6363
client.performRequest(index);

module/spring-boot-elasticsearch/src/main/java/org/springframework/boot/elasticsearch/autoconfigure/ElasticsearchClientAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.elasticsearch.autoconfigure;
1818

1919
import co.elastic.clients.elasticsearch.ElasticsearchClient;
20-
import org.elasticsearch.client.RestClient;
20+
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
2121

2222
import org.springframework.boot.autoconfigure.AutoConfiguration;
2323
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -36,7 +36,7 @@
3636
*/
3737
@AutoConfiguration(after = { ElasticsearchRestClientAutoConfiguration.class },
3838
afterName = { "org.springframework.boot.jsonb.autoconfigure.JsonbAutoConfiguration" })
39-
@ConditionalOnBean(RestClient.class)
39+
@ConditionalOnBean(Rest5Client.class)
4040
@ConditionalOnClass(ElasticsearchClient.class)
4141
@Import({ JsonpMapperConfiguration.class, ElasticsearchTransportConfiguration.class,
4242
ElasticsearchClientConfiguration.class })

module/spring-boot-elasticsearch/src/main/java/org/springframework/boot/elasticsearch/autoconfigure/ElasticsearchClientConfigurations.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
2323
import co.elastic.clients.json.jsonb.JsonbJsonpMapper;
2424
import co.elastic.clients.transport.ElasticsearchTransport;
25-
import co.elastic.clients.transport.rest_client.RestClientOptions;
26-
import co.elastic.clients.transport.rest_client.RestClientTransport;
25+
import co.elastic.clients.transport.rest5_client.Rest5ClientOptions;
26+
import co.elastic.clients.transport.rest5_client.Rest5ClientTransport;
27+
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
2728
import com.fasterxml.jackson.databind.ObjectMapper;
2829
import jakarta.json.bind.Jsonb;
2930
import jakarta.json.spi.JsonProvider;
30-
import org.elasticsearch.client.RestClient;
3131

3232
import org.springframework.beans.factory.ObjectProvider;
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -89,9 +89,9 @@ SimpleJsonpMapper simpleJsonpMapper() {
8989
static class ElasticsearchTransportConfiguration {
9090

9191
@Bean
92-
RestClientTransport restClientTransport(RestClient restClient, JsonpMapper jsonMapper,
93-
ObjectProvider<RestClientOptions> restClientOptions) {
94-
return new RestClientTransport(restClient, jsonMapper, restClientOptions.getIfAvailable());
92+
Rest5ClientTransport restClientTransport(Rest5Client restClient, JsonpMapper jsonMapper,
93+
ObjectProvider<Rest5ClientOptions> restClientOptions) {
94+
return new Rest5ClientTransport(restClient, jsonMapper, restClientOptions.getIfAvailable());
9595
}
9696

9797
}

module/spring-boot-elasticsearch/src/main/java/org/springframework/boot/elasticsearch/autoconfigure/ElasticsearchReactiveClientAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.elasticsearch.autoconfigure;
1818

1919
import co.elastic.clients.transport.ElasticsearchTransport;
20-
import org.elasticsearch.client.RestClient;
20+
import co.elastic.clients.transport.rest5_client.low_level.Rest5Client;
2121
import reactor.core.publisher.Mono;
2222

2323
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -38,7 +38,7 @@
3838
* @since 4.0.0
3939
*/
4040
@AutoConfiguration(after = ElasticsearchClientAutoConfiguration.class)
41-
@ConditionalOnBean(RestClient.class)
41+
@ConditionalOnBean(Rest5Client.class)
4242
@ConditionalOnClass({ ReactiveElasticsearchClient.class, ElasticsearchTransport.class, Mono.class })
4343
@EnableConfigurationProperties(ElasticsearchProperties.class)
4444
@Import({ ElasticsearchClientConfigurations.JsonpMapperConfiguration.class,

module/spring-boot-elasticsearch/src/main/java/org/springframework/boot/elasticsearch/autoconfigure/ElasticsearchRestClientAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.elasticsearch.autoconfigure;
1818

19-
import org.elasticsearch.client.RestClientBuilder;
19+
import co.elastic.clients.transport.rest5_client.low_level.Rest5ClientBuilder;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfiguration;
2222
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -36,7 +36,7 @@
3636
* @since 4.0.0
3737
*/
3838
@AutoConfiguration(after = SslAutoConfiguration.class)
39-
@ConditionalOnClass(RestClientBuilder.class)
39+
@ConditionalOnClass(Rest5ClientBuilder.class)
4040
@EnableConfigurationProperties(ElasticsearchProperties.class)
4141
@Import({ RestClientBuilderConfiguration.class, RestClientConfiguration.class, RestClientSnifferConfiguration.class })
4242
public final class ElasticsearchRestClientAutoConfiguration {

0 commit comments

Comments
 (0)