Skip to content

Commit 3fbc0c7

Browse files
committed
This commit is intentend to implement the request of spring-projects#1646.
1 parent 154c50b commit 3fbc0c7

File tree

11 files changed

+233
-15
lines changed

11 files changed

+233
-15
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.client.reactive;
1717

18-
import io.netty.channel.ChannelOption;
19-
import io.netty.handler.ssl.ApplicationProtocolConfig;
20-
import io.netty.handler.ssl.ClientAuth;
21-
import io.netty.handler.ssl.IdentityCipherSuiteFilter;
22-
import io.netty.handler.ssl.JdkSslContext;
23-
import io.netty.handler.timeout.ReadTimeoutHandler;
24-
import io.netty.handler.timeout.WriteTimeoutHandler;
25-
import reactor.core.publisher.Flux;
26-
import reactor.core.publisher.Mono;
27-
import reactor.netty.http.client.HttpClient;
28-
import reactor.netty.transport.ProxyProvider;
29-
3018
import java.io.IOException;
3119
import java.lang.reflect.Method;
3220
import java.net.ConnectException;
@@ -86,6 +74,7 @@
8674
import org.elasticsearch.client.Request;
8775
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
8876
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
77+
import org.elasticsearch.client.indices.GetIndexResponse;
8978
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
9079
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
9180
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
@@ -131,6 +120,18 @@
131120
import org.springframework.web.reactive.function.client.WebClient;
132121
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec;
133122

123+
import io.netty.channel.ChannelOption;
124+
import io.netty.handler.ssl.ApplicationProtocolConfig;
125+
import io.netty.handler.ssl.ClientAuth;
126+
import io.netty.handler.ssl.IdentityCipherSuiteFilter;
127+
import io.netty.handler.ssl.JdkSslContext;
128+
import io.netty.handler.timeout.ReadTimeoutHandler;
129+
import io.netty.handler.timeout.WriteTimeoutHandler;
130+
import reactor.core.publisher.Flux;
131+
import reactor.core.publisher.Mono;
132+
import reactor.netty.http.client.HttpClient;
133+
import reactor.netty.transport.ProxyProvider;
134+
134135
/**
135136
* A {@link WebClient} based {@link ReactiveElasticsearchClient} that connects to an Elasticsearch cluster using HTTP.
136137
*
@@ -144,6 +145,7 @@
144145
* @author Thomas Geese
145146
* @author Brian Clozel
146147
* @author Farid Faoudi
148+
* @author George Popides
147149
* @since 3.2
148150
* @see ClientConfiguration
149151
* @see ReactiveRestClients
@@ -757,6 +759,12 @@ public Mono<Boolean> deleteTemplate(HttpHeaders headers, DeleteIndexTemplateRequ
757759
.map(AcknowledgedResponse::isAcknowledged).next();
758760
}
759761

762+
@Override
763+
public Mono<GetIndexResponse> getIndex(HttpHeaders headers, org.elasticsearch.client.indices.GetIndexRequest getIndexRequest) {
764+
return sendRequest(getIndexRequest, requestCreator.getIndex(), GetIndexResponse.class, headers)
765+
.next();
766+
}
767+
760768
// endregion
761769

762770
// region helper functions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.elasticsearch.client.reactive;
1717

18+
import org.elasticsearch.client.indices.GetIndexResponse;
1819
import reactor.core.publisher.Flux;
1920
import reactor.core.publisher.Mono;
2021

@@ -1456,5 +1457,7 @@ default Mono<Boolean> deleteTemplate(DeleteIndexTemplateRequest deleteIndexTempl
14561457
* @since 4.1
14571458
*/
14581459
Mono<Boolean> deleteTemplate(HttpHeaders headers, DeleteIndexTemplateRequest deleteIndexTemplateRequest);
1460+
1461+
Mono<GetIndexResponse> getIndex(HttpHeaders headers, org.elasticsearch.client.indices.GetIndexRequest getIndexRequest);
14591462
}
14601463
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
/**
4141
* @author Roman Puchkovskiy
4242
* @author Farid Faoudi
43+
* @author George Popides
4344
* @since 4.0
4445
*/
4546
public interface RequestCreator {
@@ -149,6 +150,7 @@ default Function<CountRequest, Request> count() {
149150
return RequestConverters::count;
150151
}
151152

153+
default Function<org.elasticsearch.client.indices.GetIndexRequest, Request> getIndex() { return RequestConverters::getIndex; }
152154
/**
153155
* @since 4.1
154156
*/

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,22 @@ public static Request getIndex(GetIndexRequest getIndexRequest) {
692692
return request;
693693
}
694694

695+
public static Request getIndex(org.elasticsearch.client.indices.GetIndexRequest getIndexRequest) {
696+
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
697+
698+
String endpoint = endpoint(indices);
699+
Request request = new Request(HttpMethod.GET.name(), endpoint);
700+
701+
Params params = new Params(request);
702+
params.withIndicesOptions(getIndexRequest.indicesOptions());
703+
params.withLocal(getIndexRequest.local());
704+
params.withIncludeDefaults(getIndexRequest.includeDefaults());
705+
params.withHuman(getIndexRequest.humanReadable());
706+
params.withMasterTimeout(getIndexRequest.masterNodeTimeout());
707+
708+
return request;
709+
}
710+
695711
public static Request indexDelete(DeleteIndexRequest deleteIndexRequest) {
696712
String endpoint = RequestConverters.endpoint(deleteIndexRequest.indices());
697713
Request request = new Request(HttpMethod.DELETE.name(), endpoint);

src/main/java/org/springframework/data/elasticsearch/core/DefaultIndexOperations.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.client.RequestOptions;
3333
import org.elasticsearch.client.indices.CreateIndexRequest;
3434
import org.elasticsearch.client.indices.GetIndexRequest;
35+
import org.elasticsearch.client.indices.GetIndexResponse;
3536
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
3637
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
3738
import org.elasticsearch.client.indices.GetMappingsRequest;
@@ -51,6 +52,7 @@
5152
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest;
5253
import org.springframework.data.elasticsearch.core.index.TemplateData;
5354
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
55+
import org.springframework.data.elasticsearch.core.mapping.IndexInformation;
5456
import org.springframework.data.elasticsearch.core.query.AliasQuery;
5557
import org.springframework.lang.Nullable;
5658
import org.springframework.util.Assert;
@@ -60,6 +62,7 @@
6062
*
6163
* @author Peter-Josef Meisch
6264
* @author Sascha Woo
65+
* @author George Popides
6366
* @since 4.0
6467
*/
6568
class DefaultIndexOperations extends AbstractDefaultIndexOperations implements IndexOperations {
@@ -256,5 +259,16 @@ public boolean deleteTemplate(DeleteTemplateRequest deleteTemplateRequest) {
256259
client -> client.indices().deleteTemplate(deleteIndexTemplateRequest, RequestOptions.DEFAULT).isAcknowledged());
257260
}
258261

262+
@Override
263+
public List<IndexInformation> getInformation() {
264+
GetIndexRequest request = requestFactory.getIndexRequest(getIndexCoordinates());
265+
266+
return restTemplate.execute(
267+
client -> {
268+
GetIndexResponse getIndexResponse = client.indices().get(request, RequestOptions.DEFAULT);
269+
return IndexInformation.createList(getIndexResponse);
270+
});
271+
}
272+
259273
// endregion
260274
}

src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import static org.elasticsearch.client.Requests.*;
1919
import static org.springframework.util.StringUtils.*;
2020

21-
import reactor.core.publisher.Mono;
22-
21+
import java.util.List;
2322
import java.util.Map;
2423
import java.util.Set;
2524

@@ -38,7 +37,6 @@
3837
import org.slf4j.Logger;
3938
import org.slf4j.LoggerFactory;
4039
import org.springframework.core.annotation.AnnotatedElementUtils;
41-
import org.springframework.core.annotation.AnnotationAttributes;
4240
import org.springframework.dao.InvalidDataAccessApiUsageException;
4341
import org.springframework.data.elasticsearch.NoSuchIndexException;
4442
import org.springframework.data.elasticsearch.annotations.Mapping;
@@ -55,11 +53,16 @@
5553
import org.springframework.data.elasticsearch.core.index.TemplateData;
5654
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
5755
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
56+
import org.springframework.data.elasticsearch.core.mapping.IndexInformation;
57+
import org.springframework.http.HttpHeaders;
5858
import org.springframework.lang.Nullable;
5959
import org.springframework.util.Assert;
6060

61+
import reactor.core.publisher.Mono;
62+
6163
/**
6264
* @author Peter-Josef Meisch
65+
* @author George Popides
6366
* @since 4.1
6467
*/
6568
class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
@@ -304,6 +307,14 @@ public IndexCoordinates getIndexCoordinates() {
304307
return (boundClass != null) ? getIndexCoordinatesFor(boundClass) : boundIndex;
305308
}
306309

310+
@Override
311+
public Mono<List<IndexInformation>> getInformation() {
312+
org.elasticsearch.client.indices.GetIndexRequest getIndexRequest = requestFactory.getIndexRequest(getIndexCoordinates());
313+
314+
return Mono.from(operations.executeWithIndicesClient(client -> client.getIndex(HttpHeaders.EMPTY, getIndexRequest)
315+
.map(IndexInformation::createList)));
316+
}
317+
307318
private IndexCoordinates getIndexCoordinatesFor(Class<?> clazz) {
308319
return operations.getElasticsearchConverter().getMappingContext().getRequiredPersistentEntity(clazz)
309320
.getIndexCoordinates();

src/main/java/org/springframework/data/elasticsearch/core/DefaultTransportIndexOperations.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
3030
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3131
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
32+
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
33+
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
3234
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
3335
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
3436
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
@@ -57,6 +59,7 @@
5759
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest;
5860
import org.springframework.data.elasticsearch.core.index.TemplateData;
5961
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
62+
import org.springframework.data.elasticsearch.core.mapping.IndexInformation;
6063
import org.springframework.data.elasticsearch.core.query.AliasQuery;
6164
import org.springframework.lang.Nullable;
6265
import org.springframework.util.Assert;
@@ -66,6 +69,7 @@
6669
*
6770
* @author Peter-Josef Meisch
6871
* @author Sascha Woo
72+
* @author George Popides
6973
* @since 4.0
7074
*/
7175
class DefaultTransportIndexOperations extends AbstractDefaultIndexOperations implements IndexOperations {
@@ -296,4 +300,16 @@ public boolean deleteTemplate(DeleteTemplateRequest deleteTemplateRequest) {
296300
deleteTemplateRequest);
297301
return client.admin().indices().deleteTemplate(deleteIndexTemplateRequest).actionGet().isAcknowledged();
298302
}
303+
304+
@Override
305+
public List<IndexInformation> getInformation() {
306+
GetIndexRequest getIndexRequest = new GetIndexRequest();
307+
IndexCoordinates index = getIndexCoordinates();
308+
309+
getIndexRequest.indices(index.getIndexNames());
310+
311+
GetIndexResponse response = client.admin().indices().getIndex(getIndexRequest).actionGet();
312+
313+
return IndexInformation.createList(response);
314+
}
299315
}

src/main/java/org/springframework/data/elasticsearch/core/IndexOperations.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest;
3030
import org.springframework.data.elasticsearch.core.index.TemplateData;
3131
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
32+
import org.springframework.data.elasticsearch.core.mapping.IndexInformation;
3233
import org.springframework.data.elasticsearch.core.query.AliasQuery;
3334
import org.springframework.lang.Nullable;
3435

@@ -317,5 +318,7 @@ default boolean deleteTemplate(String templateName) {
317318
*/
318319
IndexCoordinates getIndexCoordinates();
319320

321+
List<IndexInformation> getInformation();
322+
320323
// endregion
321324
}

src/main/java/org/springframework/data/elasticsearch/core/ReactiveIndexOperations.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core;
1717

18+
import org.springframework.data.elasticsearch.core.mapping.IndexInformation;
1819
import reactor.core.publisher.Mono;
1920

21+
import java.util.List;
2022
import java.util.Map;
2123
import java.util.Set;
2224

@@ -284,5 +286,6 @@ default Mono<Boolean> deleteTemplate(String templateName) {
284286
*/
285287
IndexCoordinates getIndexCoordinates();
286288

289+
Mono<List<IndexInformation>> getInformation();
287290
// endregion
288291
}

0 commit comments

Comments
 (0)