Skip to content

Commit 4a0e7cc

Browse files
committed
Polishing
1 parent c5db583 commit 4a0e7cc

16 files changed

+230
-228
lines changed

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
import org.elasticsearch.index.get.GetResult;
8989
import org.elasticsearch.index.reindex.BulkByScrollResponse;
9090
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
91-
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
9291
import org.elasticsearch.index.reindex.ReindexRequest;
92+
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
9393
import org.elasticsearch.rest.BytesRestResponse;
9494
import org.elasticsearch.rest.RestStatus;
9595
import org.elasticsearch.script.mustache.SearchTemplateRequest;
@@ -105,7 +105,6 @@
105105
import org.reactivestreams.Publisher;
106106
import org.springframework.data.elasticsearch.RestStatusException;
107107
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
108-
import org.springframework.data.elasticsearch.core.ResponseConverter;
109108
import org.springframework.data.elasticsearch.client.ClientConfiguration;
110109
import org.springframework.data.elasticsearch.client.ClientLogger;
111110
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
@@ -115,6 +114,7 @@
115114
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient.Indices;
116115
import org.springframework.data.elasticsearch.client.util.NamedXContents;
117116
import org.springframework.data.elasticsearch.client.util.ScrollState;
117+
import org.springframework.data.elasticsearch.core.ResponseConverter;
118118
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
119119
import org.springframework.data.util.Lazy;
120120
import org.springframework.http.HttpHeaders;
@@ -150,7 +150,6 @@
150150
* @see ClientConfiguration
151151
* @see ReactiveRestClients
152152
*/
153-
// todo package private after refactoring
154153
public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearchClient, Indices, Cluster {
155154

156155
private final HostProvider<?> hostProvider;
@@ -514,14 +513,12 @@ public Mono<BulkResponse> bulk(HttpHeaders headers, BulkRequest bulkRequest) {
514513

515514
@Override
516515
public Mono<BulkByScrollResponse> reindex(HttpHeaders headers, ReindexRequest reindexRequest) {
517-
return sendRequest(reindexRequest, requestCreator.reindex(), BulkByScrollResponse.class, headers)
518-
.next();
516+
return sendRequest(reindexRequest, requestCreator.reindex(), BulkByScrollResponse.class, headers).next();
519517
}
520518

521519
@Override
522520
public Mono<String> submitReindex(HttpHeaders headers, ReindexRequest reindexRequest) {
523-
return sendRequest(reindexRequest, requestCreator.submitReindex(), TaskSubmissionResponse.class, headers)
524-
.next()
521+
return sendRequest(reindexRequest, requestCreator.submitReindex(), TaskSubmissionResponse.class, headers).next()
525522
.map(TaskSubmissionResponse::getTask);
526523
}
527524

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
import org.elasticsearch.index.get.GetResult;
5454
import org.elasticsearch.index.reindex.BulkByScrollResponse;
5555
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
56-
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
5756
import org.elasticsearch.index.reindex.ReindexRequest;
57+
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
5858
import org.elasticsearch.script.mustache.SearchTemplateRequest;
5959
import org.elasticsearch.search.SearchHit;
6060
import org.elasticsearch.search.aggregations.Aggregation;
@@ -722,7 +722,7 @@ default Mono<BulkResponse> bulk(BulkRequest bulkRequest) {
722722
* @return the {@link Mono} emitting the response
723723
* @since 4.4
724724
*/
725-
default Mono<BulkByScrollResponse> reindex(Consumer<ReindexRequest> consumer){
725+
default Mono<BulkByScrollResponse> reindex(Consumer<ReindexRequest> consumer) {
726726

727727
ReindexRequest reindexRequest = new ReindexRequest();
728728
consumer.accept(reindexRequest);
@@ -736,7 +736,7 @@ default Mono<BulkByScrollResponse> reindex(Consumer<ReindexRequest> consumer){
736736
* @return the {@link Mono} emitting the response
737737
* @since 4.4
738738
*/
739-
default Mono<BulkByScrollResponse> reindex(ReindexRequest reindexRequest){
739+
default Mono<BulkByScrollResponse> reindex(ReindexRequest reindexRequest) {
740740
return reindex(HttpHeaders.EMPTY, reindexRequest);
741741
}
742742

@@ -757,7 +757,7 @@ default Mono<BulkByScrollResponse> reindex(ReindexRequest reindexRequest){
757757
* @return the {@link Mono} emitting the task id
758758
* @since 4.4
759759
*/
760-
default Mono<String> submitReindex(Consumer<ReindexRequest> consumer){
760+
default Mono<String> submitReindex(Consumer<ReindexRequest> consumer) {
761761

762762
ReindexRequest reindexRequest = new ReindexRequest();
763763
consumer.accept(reindexRequest);
@@ -771,7 +771,7 @@ default Mono<String> submitReindex(Consumer<ReindexRequest> consumer){
771771
* @return the {@link Mono} emitting the task id
772772
* @since 4.4
773773
*/
774-
default Mono<String> submitReindex(ReindexRequest reindexRequest){
774+
default Mono<String> submitReindex(ReindexRequest reindexRequest) {
775775
return submitReindex(HttpHeaders.EMPTY, reindexRequest);
776776
}
777777

@@ -784,6 +784,7 @@ default Mono<String> submitReindex(ReindexRequest reindexRequest){
784784
* @since 4.4
785785
*/
786786
Mono<String> submitReindex(HttpHeaders headers, ReindexRequest reindexRequest);
787+
787788
/**
788789
* Compose the actual command/s to run against Elasticsearch using the underlying {@link WebClient connection}.
789790
* {@link #execute(ReactiveElasticsearchClientCallback) Execute} selects an active server from the available ones and

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,14 @@ default Function<ClusterHealthRequest, Request> clusterHealth() {
294294
/**
295295
* @since 4.4
296296
*/
297-
default Function<ReindexRequest, Request> reindex() { return RequestConverters::reindex; }
297+
default Function<ReindexRequest, Request> reindex() {
298+
return RequestConverters::reindex;
299+
}
298300

299301
/**
300302
* @since 4.4
301303
*/
302-
default Function<ReindexRequest, Request> submitReindex() { return RequestConverters::submitReindex; }
304+
default Function<ReindexRequest, Request> submitReindex() {
305+
return RequestConverters::submitReindex;
306+
}
303307
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,17 @@ private static Request prepareReindexRequest(ReindexRequest reindexRequest, bool
547547
.withTimeout(reindexRequest.getTimeout()).withWaitForActiveShards(reindexRequest.getWaitForActiveShards())
548548
.withRequestsPerSecond(reindexRequest.getRequestsPerSecond());
549549

550-
if(reindexRequest.getDestination().isRequireAlias()){
550+
if (reindexRequest.getDestination().isRequireAlias()) {
551551
params.putParam("require_alias", Boolean.TRUE.toString());
552552
}
553+
553554
if (reindexRequest.getScrollTime() != null) {
554555
params.putParam("scroll", reindexRequest.getScrollTime());
555556
}
557+
556558
params.putParam("slices", Integer.toString(reindexRequest.getSlices()));
557-
if(reindexRequest.getMaxDocs() > -1){
559+
560+
if (reindexRequest.getMaxDocs() > -1) {
558561
params.putParam("max_docs", Integer.toString(reindexRequest.getMaxDocs()));
559562
}
560563
request.setEntity(createEntity(reindexRequest, REQUEST_BODY_CONTENT_TYPE));

Diff for: src/main/java/org/springframework/data/elasticsearch/core/DocumentOperations.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
import java.util.Collection;
1919
import java.util.List;
2020

21-
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
22-
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
2321
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
2422
import org.springframework.data.elasticsearch.core.query.BulkOptions;
2523
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
2624
import org.springframework.data.elasticsearch.core.query.IndexQuery;
2725
import org.springframework.data.elasticsearch.core.query.Query;
2826
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
2927
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
28+
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
29+
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
3030
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
3131
import org.springframework.lang.Nullable;
3232

@@ -327,10 +327,9 @@ default void bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index) {
327327
ByQueryResponse updateByQuery(UpdateQuery updateQuery, IndexCoordinates index);
328328

329329
/**
330-
* Copies documents from a source to a destination.
331-
* The source can be any existing index, alias, or data stream. The destination must differ from the source.
332-
* For example, you cannot reindex a data stream into itself.
333-
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
330+
* Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The
331+
* destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see
332+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
334333
*
335334
* @param reindexRequest reindex request parameters
336335
* @return the reindex response
@@ -339,8 +338,7 @@ default void bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index) {
339338
ReindexResponse reindex(ReindexRequest reindexRequest);
340339

341340
/**
342-
* Submits a reindex task.
343-
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
341+
* Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
344342
*
345343
* @param reindexRequest reindex request parameters
346344
* @return the task id

Diff for: src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@
6161
import org.springframework.data.elasticsearch.core.cluster.ElasticsearchClusterOperations;
6262
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
6363
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
64-
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
6564
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
66-
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
6765
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
6866
import org.springframework.data.elasticsearch.core.query.BulkOptions;
6967
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
@@ -73,6 +71,8 @@
7371
import org.springframework.data.elasticsearch.core.query.Query;
7472
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
7573
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
74+
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
75+
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
7676
import org.springframework.lang.Nullable;
7777
import org.springframework.util.Assert;
7878

@@ -265,7 +265,7 @@ public ByQueryResponse updateByQuery(UpdateQuery query, IndexCoordinates index)
265265
Assert.notNull(query, "query must not be null");
266266
Assert.notNull(index, "index must not be null");
267267

268-
final UpdateByQueryRequest updateByQueryRequest = requestFactory.updateByQueryRequest(query, index);
268+
UpdateByQueryRequest updateByQueryRequest = requestFactory.updateByQueryRequest(query, index);
269269

270270
if (query.getRefreshPolicy() == null && getRefreshPolicy() != null) {
271271
updateByQueryRequest.setRefresh(getRefreshPolicy() == RefreshPolicy.IMMEDIATE);
@@ -285,8 +285,8 @@ public ReindexResponse reindex(ReindexRequest postReindexRequest) {
285285

286286
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
287287

288-
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
289-
final BulkByScrollResponse bulkByScrollResponse = execute(
288+
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
289+
BulkByScrollResponse bulkByScrollResponse = execute(
290290
client -> client.reindex(reindexRequest, RequestOptions.DEFAULT));
291291
return ResponseConverter.reindexResponseOf(bulkByScrollResponse);
292292
}
@@ -295,9 +295,8 @@ public ReindexResponse reindex(ReindexRequest postReindexRequest) {
295295
public String submitReindex(ReindexRequest postReindexRequest) {
296296
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
297297

298-
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
299-
return execute(
300-
client -> client.submitReindexTask(reindexRequest, RequestOptions.DEFAULT).getTask());
298+
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
299+
return execute(client -> client.submitReindexTask(reindexRequest, RequestOptions.DEFAULT).getTask());
301300
}
302301

303302
public List<IndexedObjectInformation> doBulkOperation(List<?> queries, BulkOptions bulkOptions,

Diff for: src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core;
1717

18-
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
19-
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
2018
import reactor.core.publisher.Flux;
2119
import reactor.core.publisher.Mono;
2220

@@ -30,6 +28,8 @@
3028
import org.springframework.data.elasticsearch.core.query.Query;
3129
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
3230
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
31+
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
32+
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
3333
import org.springframework.util.Assert;
3434

3535
/**
@@ -307,10 +307,9 @@ default Mono<Void> bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index)
307307
Mono<ByQueryResponse> updateByQuery(UpdateQuery updateQuery, IndexCoordinates index);
308308

309309
/**
310-
* Copies documents from a source to a destination.
311-
* The source can be any existing index, alias, or data stream. The destination must differ from the source.
312-
* For example, you cannot reindex a data stream into itself.
313-
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
310+
* Copies documents from a source to a destination. The source can be any existing index, alias, or data stream. The
311+
* destination must differ from the source. For example, you cannot reindex a data stream into itself. (@see
312+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
314313
*
315314
* @param reindexRequest reindex request parameters
316315
* @return a {@link Mono} emitting the reindex response
@@ -319,8 +318,7 @@ default Mono<Void> bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index)
319318
Mono<ReindexResponse> reindex(ReindexRequest reindexRequest);
320319

321320
/**
322-
* Submits a reindex task.
323-
* (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
321+
* Submits a reindex task. (@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html)
324322
*
325323
* @param reindexRequest reindex request parameters
326324
* @return a {@link Mono} emitting the {@literal task} id.

Diff for: src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
import org.springframework.data.elasticsearch.core.event.ReactiveAfterLoadCallback;
7171
import org.springframework.data.elasticsearch.core.event.ReactiveAfterSaveCallback;
7272
import org.springframework.data.elasticsearch.core.event.ReactiveBeforeConvertCallback;
73-
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
74-
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
7573
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
7674
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
7775
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
@@ -84,6 +82,8 @@
8482
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
8583
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
8684
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
85+
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
86+
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
8787
import org.springframework.data.elasticsearch.core.routing.DefaultRoutingResolver;
8888
import org.springframework.data.elasticsearch.core.routing.RoutingResolver;
8989
import org.springframework.data.elasticsearch.core.suggest.response.Suggest;
@@ -618,7 +618,7 @@ public Mono<ReindexResponse> reindex(ReindexRequest postReindexRequest) {
618618
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
619619

620620
return Mono.defer(() -> {
621-
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
621+
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
622622
return Mono.from(execute(client -> client.reindex(reindexRequest))).map(ResponseConverter::reindexResponseOf);
623623
});
624624
}
@@ -629,7 +629,7 @@ public Mono<String> submitReindex(ReindexRequest postReindexRequest) {
629629
Assert.notNull(postReindexRequest, "postReindexRequest must not be null");
630630

631631
return Mono.defer(() -> {
632-
final org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
632+
org.elasticsearch.index.reindex.ReindexRequest reindexRequest = requestFactory.reindexRequest(postReindexRequest);
633633
return Mono.from(execute(client -> client.submitReindex(reindexRequest)));
634634
});
635635
}

0 commit comments

Comments
 (0)