diff --git a/src/main/java/org/springframework/data/elasticsearch/client/reactive/DefaultReactiveElasticsearchClient.java b/src/main/java/org/springframework/data/elasticsearch/client/reactive/DefaultReactiveElasticsearchClient.java index 918630c10..f38917131 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/reactive/DefaultReactiveElasticsearchClient.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/reactive/DefaultReactiveElasticsearchClient.java @@ -48,14 +48,9 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushResponse; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; @@ -84,13 +79,18 @@ import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.GetAliasesResponse; import org.elasticsearch.client.Request; +import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.GetFieldMappingsRequest; import org.elasticsearch.client.indices.GetFieldMappingsResponse; +import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexResponse; import org.elasticsearch.client.indices.GetIndexTemplatesRequest; import org.elasticsearch.client.indices.GetIndexTemplatesResponse; +import org.elasticsearch.client.indices.GetMappingsRequest; +import org.elasticsearch.client.indices.GetMappingsResponse; import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; +import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -646,13 +646,22 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch // region indices operations @Override - public Mono createIndex(HttpHeaders headers, CreateIndexRequest createIndexRequest) { + public Mono createIndex(HttpHeaders headers, + org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest) { return sendRequest(createIndexRequest, requestCreator.indexCreate(), AcknowledgedResponse.class, headers) // .map(AcknowledgedResponse::isAcknowledged) // .next(); } + @Override + public Mono createIndex(HttpHeaders headers, CreateIndexRequest createIndexRequest) { + + return sendRequest(createIndexRequest, requestCreator.createIndexRequest(), AcknowledgedResponse.class, headers) // + .map(AcknowledgedResponse::isAcknowledged) // + .next(); + } + @Override public Mono closeIndex(HttpHeaders headers, CloseIndexRequest closeIndexRequest) { @@ -661,14 +670,21 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch } @Override - public Mono existsIndex(HttpHeaders headers, GetIndexRequest request) { + public Mono existsIndex(HttpHeaders headers, org.elasticsearch.action.admin.indices.get.GetIndexRequest request) { return sendRequest(request, requestCreator.indexExists(), RawActionResponse.class, headers) // .flatMap(response -> response.releaseBody().thenReturn(response.statusCode().is2xxSuccessful())) // .next(); } - @Override + @Override + public Mono existsIndex(HttpHeaders headers, GetIndexRequest request) { + return sendRequest(request, requestCreator.indexExistsRequest(), RawActionResponse.class, headers) // + .flatMap(response -> response.releaseBody().thenReturn(response.statusCode().is2xxSuccessful())) // + .next(); + } + + @Override public Mono deleteIndex(HttpHeaders headers, DeleteIndexRequest request) { return sendRequest(request, requestCreator.indexDelete(), AcknowledgedResponse.class, headers) // @@ -683,9 +699,17 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch .then(); } + @Override + public Mono getMapping(HttpHeaders headers, + org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) { + return sendRequest(getMappingsRequest, requestCreator.getMapping(), + org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse.class, headers).next(); + } + @Override public Mono getMapping(HttpHeaders headers, GetMappingsRequest getMappingsRequest) { - return sendRequest(getMappingsRequest, requestCreator.getMapping(), GetMappingsResponse.class, headers).next(); + return sendRequest(getMappingsRequest, requestCreator.getMappingRequest(), GetMappingsResponse.class, headers) // + .next(); } @Override @@ -701,13 +725,21 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch } @Override - public Mono putMapping(HttpHeaders headers, PutMappingRequest putMappingRequest) { + public Mono putMapping(HttpHeaders headers, + org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) { return sendRequest(putMappingRequest, requestCreator.putMapping(), AcknowledgedResponse.class, headers) // .map(AcknowledgedResponse::isAcknowledged) // .next(); } + @Override + public Mono putMapping(HttpHeaders headers, PutMappingRequest putMappingRequest) { + return sendRequest(putMappingRequest, requestCreator.putMappingRequest(), AcknowledgedResponse.class, headers) // + .map(AcknowledgedResponse::isAcknowledged) // + .next(); + } + @Override public Mono openIndex(HttpHeaders headers, OpenIndexRequest request) { @@ -760,8 +792,7 @@ public class DefaultReactiveElasticsearchClient implements ReactiveElasticsearch } @Override - public Mono getIndex(HttpHeaders headers, - org.elasticsearch.client.indices.GetIndexRequest getIndexRequest) { + public Mono getIndex(HttpHeaders headers, GetIndexRequest getIndexRequest) { return sendRequest(getIndexRequest, requestCreator.getIndex(), GetIndexResponse.class, headers).next(); } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClient.java b/src/main/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClient.java index 196d0fb13..1d1cca41d 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClient.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClient.java @@ -15,6 +15,11 @@ */ package org.springframework.data.elasticsearch.client.reactive; +import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.client.indices.GetIndexRequest; +import org.elasticsearch.client.indices.GetMappingsRequest; +import org.elasticsearch.client.indices.GetMappingsResponse; +import org.elasticsearch.client.indices.PutMappingRequest; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -25,13 +30,8 @@ import java.util.function.Consumer; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; @@ -748,42 +748,74 @@ public interface ReactiveElasticsearchClient { interface Indices { /** - * Execute the given {@link GetIndexRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.get.GetIndexRequest} against the {@literal indices} API. * * @param consumer never {@literal null}. * @return the {@link Mono} emitting {@literal true} if the index exists, {@literal false} otherwise. * @see Indices * Exists API on elastic.co + * @deprecated since 4.2 */ - default Mono existsIndex(Consumer consumer) { + @Deprecated + default Mono existsIndex(Consumer consumer) { - GetIndexRequest request = new GetIndexRequest(); + org.elasticsearch.action.admin.indices.get.GetIndexRequest request = + new org.elasticsearch.action.admin.indices.get.GetIndexRequest(); consumer.accept(request); return existsIndex(request); } /** - * Execute the given {@link GetIndexRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.get.GetIndexRequest} against the {@literal indices} API. * * @param getIndexRequest must not be {@literal null}. * @return the {@link Mono} emitting {@literal true} if the index exists, {@literal false} otherwise. * @see Indices * Exists API on elastic.co + * @deprecated since 4.2, use {@link #existsIndex(GetIndexRequest)} */ - default Mono existsIndex(GetIndexRequest getIndexRequest) { + @Deprecated + default Mono existsIndex(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest) { return existsIndex(HttpHeaders.EMPTY, getIndexRequest); } /** - * Execute the given {@link GetIndexRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.get.GetIndexRequest} against the {@literal indices} API. * * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. * @param getIndexRequest must not be {@literal null}. * @return the {@link Mono} emitting {@literal true} if the index exists, {@literal false} otherwise. * @see Indices * Exists API on elastic.co + * @deprecated since 4.2, use {@link #existsIndex(HttpHeaders, GetIndexRequest)} */ - Mono existsIndex(HttpHeaders headers, GetIndexRequest getIndexRequest); + @Deprecated + Mono existsIndex(HttpHeaders headers, org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest); + + /** + * Execute the given {@link GetIndexRequest} against the {@literal indices} API. + * + * @param getIndexRequest must not be {@literal null}. + * @return the {@link Mono} emitting {@literal true} if the index exists, {@literal false} otherwise. + * @see Indices + * Exists API on elastic.co + * @since 4.2 + */ + default Mono existsIndex(GetIndexRequest getIndexRequest) { + return existsIndex(HttpHeaders.EMPTY, getIndexRequest); + } + + /** + * Execute the given {@link GetIndexRequest} against the {@literal indices} API. + * + * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. + * @param getIndexRequest must not be {@literal null}. + * @return the {@link Mono} emitting {@literal true} if the index exists, {@literal false} otherwise. + * @see Indices + * Exists API on elastic.co + * @since 4.2 + */ + Mono existsIndex(HttpHeaders headers, GetIndexRequest getIndexRequest); /** * Execute the given {@link DeleteIndexRequest} against the {@literal indices} API. @@ -827,21 +859,53 @@ public interface ReactiveElasticsearchClient { Mono deleteIndex(HttpHeaders headers, DeleteIndexRequest deleteIndexRequest); /** - * Execute the given {@link CreateIndexRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.create.CreateIndexRequest} against the {@literal indices} API. * * @param consumer never {@literal null}. * @return a {@link Mono} signalling successful operation completion or an {@link Mono#error(Throwable) error} if * eg. the index already exist. * @see Indices * Create API on elastic.co + * @deprecated since 4.2 */ - default Mono createIndex(Consumer consumer) { + @Deprecated + default Mono createIndex(Consumer consumer) { - CreateIndexRequest request = new CreateIndexRequest(); + org.elasticsearch.action.admin.indices.create.CreateIndexRequest request = + new org.elasticsearch.action.admin.indices.create.CreateIndexRequest(); consumer.accept(request); return createIndex(request); } + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.create.CreateIndexRequest} against the {@literal indices} API. + * + * @param createIndexRequest must not be {@literal null}. + * @return a {@link Mono} signalling successful operation completion or an {@link Mono#error(Throwable) error} if + * eg. the index already exist. + * @see Indices + * Create API on elastic.co + * @deprecated since 4.2, use {@link #createIndex(CreateIndexRequest)} + */ + @Deprecated + default Mono createIndex(org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest) { + return createIndex(HttpHeaders.EMPTY, createIndexRequest); + } + + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.create.CreateIndexRequest} against the {@literal indices} API. + * + * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. + * @param createIndexRequest must not be {@literal null}. + * @return a {@link Mono} signalling successful operation completion or an {@link Mono#error(Throwable) error} if + * eg. the index already exist. + * @see Indices + * Create API on elastic.co + * @deprecated since 4.2, use {@link #createIndex(HttpHeaders, CreateIndexRequest)} + */ + @Deprecated + Mono createIndex(HttpHeaders headers, org.elasticsearch.action.admin.indices.create.CreateIndexRequest createIndexRequest); + /** * Execute the given {@link CreateIndexRequest} against the {@literal indices} API. * @@ -850,6 +914,7 @@ public interface ReactiveElasticsearchClient { * eg. the index already exist. * @see Indices * Create API on elastic.co + * @since 4.2 */ default Mono createIndex(CreateIndexRequest createIndexRequest) { return createIndex(HttpHeaders.EMPTY, createIndexRequest); @@ -864,6 +929,7 @@ public interface ReactiveElasticsearchClient { * eg. the index already exist. * @see Indices * Create API on elastic.co + * @since 4.2 */ Mono createIndex(HttpHeaders headers, CreateIndexRequest createIndexRequest); @@ -991,7 +1057,7 @@ public interface ReactiveElasticsearchClient { Mono refreshIndex(HttpHeaders headers, RefreshRequest refreshRequest); /** - * Execute the given {@link PutMappingRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. * * @param consumer never {@literal null}. * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index @@ -1001,12 +1067,12 @@ public interface ReactiveElasticsearchClient { * @deprecated since 4.1, use {@link #putMapping(Consumer)} */ @Deprecated - default Mono updateMapping(Consumer consumer) { + default Mono updateMapping(Consumer consumer) { return putMapping(consumer); } /** - * Execute the given {@link PutMappingRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. * * @param putMappingRequest must not be {@literal null}. * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index @@ -1016,12 +1082,12 @@ public interface ReactiveElasticsearchClient { * @deprecated since 4.1, use {@link #putMapping(PutMappingRequest)} */ @Deprecated - default Mono updateMapping(PutMappingRequest putMappingRequest) { + default Mono updateMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) { return putMapping(putMappingRequest); } /** - * Execute the given {@link PutMappingRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. * * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. * @param putMappingRequest must not be {@literal null}. @@ -1032,26 +1098,58 @@ public interface ReactiveElasticsearchClient { * @deprecated since 4.1, use {@link #putMapping(HttpHeaders, PutMappingRequest)} */ @Deprecated - default Mono updateMapping(HttpHeaders headers, PutMappingRequest putMappingRequest) { + default Mono updateMapping(HttpHeaders headers, org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) { return putMapping(headers, putMappingRequest); } /** - * Execute the given {@link PutMappingRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. * * @param consumer never {@literal null}. * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index * does not exist. * @see Indices * Put Mapping API on elastic.co + * @deprecated since 4.2 */ - default Mono putMapping(Consumer consumer) { + @Deprecated + default Mono putMapping(Consumer consumer) { - PutMappingRequest request = new PutMappingRequest(); + org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest request = + new org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest(); consumer.accept(request); return putMapping(request); } + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. + * + * @param putMappingRequest must not be {@literal null}. + * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index + * does not exist. + * @see Indices + * Put Mapping API on elastic.co + * @deprecated since 4.2, use {@link #putMapping(PutMappingRequest)} + */ + @Deprecated + default Mono putMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) { + return putMapping(HttpHeaders.EMPTY, putMappingRequest); + } + + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest} against the {@literal indices} API. + * + * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. + * @param putMappingRequest must not be {@literal null}. + * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index + * does not exist. + * @see Indices + * Put Mapping API on elastic.co + * @deprecated since 4.2, use {@link #putMapping(HttpHeaders, PutMappingRequest)} + */ + @Deprecated + Mono putMapping(HttpHeaders headers, org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest); + /** * Execute the given {@link PutMappingRequest} against the {@literal indices} API. * @@ -1060,6 +1158,7 @@ public interface ReactiveElasticsearchClient { * does not exist. * @see Indices * Put Mapping API on elastic.co + * @since 4.2 */ default Mono putMapping(PutMappingRequest putMappingRequest) { return putMapping(HttpHeaders.EMPTY, putMappingRequest); @@ -1074,6 +1173,7 @@ public interface ReactiveElasticsearchClient { * does not exist. * @see Indices * Put Mapping API on elastic.co + * @since 4.2 */ Mono putMapping(HttpHeaders headers, PutMappingRequest putMappingRequest); @@ -1163,7 +1263,7 @@ public interface ReactiveElasticsearchClient { Mono getSettings(HttpHeaders headers, GetSettingsRequest getSettingsRequest); /** - * Execute the given {@link GetMappingsRequest} against the {@literal indices} API. + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest} against the {@literal indices} API. * * @param consumer never {@literal null}. * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index @@ -1171,14 +1271,51 @@ public interface ReactiveElasticsearchClient { * @see Indices * Flush API on elastic.co * @since 4.1 + * @deprecated since 4.2 */ - default Mono getMapping(Consumer consumer) { + @Deprecated + default Mono getMapping( + Consumer consumer) { - GetMappingsRequest request = new GetMappingsRequest(); + org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest request = + new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest(); consumer.accept(request); return getMapping(request); } + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest} against the {@literal indices} API. + * + * @param getMappingsRequest must not be {@literal null}. + * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index + * does not exist. + * @see Indices + * Flush API on elastic.co + * @since 4.1 + * @deprecated since 4.2, use {@link #getMapping(GetMappingsRequest)} + */ + @Deprecated + default Mono getMapping( + org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) { + return getMapping(HttpHeaders.EMPTY, getMappingsRequest); + } + + /** + * Execute the given {@link org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest} against the {@literal indices} API. + * + * @param headers Use {@link HttpHeaders} to provide eg. authentication data. Must not be {@literal null}. + * @param getMappingsRequest must not be {@literal null}. + * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index + * does not exist. + * @see Indices + * Flush API on elastic.co + * @since 4.1 + * @deprecated since 4.2, use {@link #getMapping(HttpHeaders, GetMappingsRequest)} + */ + @Deprecated + Mono getMapping(HttpHeaders headers, + org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest); + /** * Execute the given {@link GetMappingsRequest} against the {@literal indices} API. * @@ -1186,8 +1323,8 @@ public interface ReactiveElasticsearchClient { * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index * does not exist. * @see Indices - * Flush API on elastic.co - * @since 4.1 + * Get mapping API on elastic.co + * @since 4.2 */ default Mono getMapping(GetMappingsRequest getMappingsRequest) { return getMapping(HttpHeaders.EMPTY, getMappingsRequest); @@ -1201,8 +1338,8 @@ public interface ReactiveElasticsearchClient { * @return a {@link Mono} signalling operation completion or an {@link Mono#error(Throwable) error} if eg. the index * does not exist. * @see Indices - * Flush API on elastic.co - * @since 4.1 + * Get mapping API on elastic.co + * @since 4.2 */ Mono getMapping(HttpHeaders headers, GetMappingsRequest getMappingsRequest); @@ -1465,8 +1602,8 @@ public interface ReactiveElasticsearchClient { * @return the {@link Mono} emitting the response * @since 4.2 */ - default Mono getIndex(Consumer consumer) { - org.elasticsearch.client.indices.GetIndexRequest getIndexRequest = new org.elasticsearch.client.indices.GetIndexRequest(); + default Mono getIndex(Consumer consumer) { + GetIndexRequest getIndexRequest = new GetIndexRequest(); consumer.accept(getIndexRequest); return getIndex(getIndexRequest); } @@ -1478,7 +1615,7 @@ public interface ReactiveElasticsearchClient { * @return the {@link Mono} emitting the response * @since 4.2 */ - default Mono getIndex(org.elasticsearch.client.indices.GetIndexRequest getIndexRequest) { + default Mono getIndex(GetIndexRequest getIndexRequest) { return getIndex(HttpHeaders.EMPTY, getIndexRequest); } @@ -1490,7 +1627,6 @@ public interface ReactiveElasticsearchClient { * @return the {@link Mono} emitting the response * @since 4.2 */ - Mono getIndex(HttpHeaders headers, - org.elasticsearch.client.indices.GetIndexRequest getIndexRequest); + Mono getIndex(HttpHeaders headers, GetIndexRequest getIndexRequest); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/reactive/RequestCreator.java b/src/main/java/org/springframework/data/elasticsearch/client/reactive/RequestCreator.java index 79436f986..a2beccc9e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/reactive/RequestCreator.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/reactive/RequestCreator.java @@ -6,12 +6,8 @@ import java.util.function.Function; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; @@ -28,10 +24,14 @@ import org.elasticsearch.action.search.SearchScrollRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.client.Request; import org.elasticsearch.client.core.CountRequest; +import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.GetFieldMappingsRequest; +import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexTemplatesRequest; +import org.elasticsearch.client.indices.GetMappingsRequest; import org.elasticsearch.client.indices.IndexTemplatesExistRequest; import org.elasticsearch.client.indices.PutIndexTemplateRequest; +import org.elasticsearch.client.indices.PutMappingRequest; import org.elasticsearch.index.reindex.DeleteByQueryRequest; import org.elasticsearch.index.reindex.UpdateByQueryRequest; import org.springframework.data.elasticsearch.UncategorizedElasticsearchException; @@ -114,15 +114,37 @@ public interface RequestCreator { // --> INDICES - default Function indexExists() { + /** + * @deprecated since 4.2 + */ + @Deprecated + default Function indexExists() { return RequestConverters::indexExists; } + /** + * @since 4.2 + */ + default Function indexExistsRequest() { + return RequestConverters::indexExists; + } + default Function indexDelete() { return RequestConverters::indexDelete; } - default Function indexCreate() { + /** + * @deprecated since 4.2 + */ + @Deprecated + default Function indexCreate() { + return RequestConverters::indexCreate; + } + + /** + * @since 4.2 + */ + default Function createIndexRequest() { return RequestConverters::indexCreate; } @@ -138,10 +160,21 @@ public interface RequestCreator { return RequestConverters::indexRefresh; } - default Function putMapping() { + /** + * @deprecated since 4.2 + */ + @Deprecated + default Function putMapping() { return RequestConverters::putMapping; } + /** + * @since 4.2 + */ + default Function putMappingRequest() { + return RequestConverters::putMapping; + } + default Function flushIndex() { return RequestConverters::flushIndex; } @@ -159,11 +192,20 @@ public interface RequestCreator { /** * @since 4.1 + * @deprecated since 4.2 */ - default Function getMapping() { + @Deprecated + default Function getMapping() { return RequestConverters::getMapping; } + /** + * @since 4.2 + */ + default Function getMappingRequest() { + return RequestConverters::getMapping; + } + /** * @since 4.1 */ @@ -216,7 +258,7 @@ public interface RequestCreator { /** * @since 4.2 */ - default Function getIndex() { + default Function getIndex() { return RequestConverters::getIndex; } } diff --git a/src/main/java/org/springframework/data/elasticsearch/client/util/RequestConverters.java b/src/main/java/org/springframework/data/elasticsearch/client/util/RequestConverters.java index 4fefaaabb..b6dd59b35 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/util/RequestConverters.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/util/RequestConverters.java @@ -735,6 +735,22 @@ public class RequestConverters { return request; } + public static Request indexExists(org.elasticsearch.client.indices.GetIndexRequest getIndexRequest) { + // this can be called with no indices as argument by transport client, not via REST though + if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) { + throw new IllegalArgumentException("indices are mandatory"); + } + String endpoint = endpoint(getIndexRequest.indices(), ""); + Request request = new Request(HttpMethod.HEAD.name(), endpoint); + + Params params = new Params(request); + params.withLocal(getIndexRequest.local()); + params.withHuman(getIndexRequest.humanReadable()); + params.withIndicesOptions(getIndexRequest.indicesOptions()); + params.withIncludeDefaults(getIndexRequest.includeDefaults()); + return request; + } + public static Request indexOpen(OpenIndexRequest openIndexRequest) { String endpoint = RequestConverters.endpoint(openIndexRequest.indices(), "_open"); Request request = new Request(HttpMethod.POST.name(), endpoint); @@ -771,6 +787,19 @@ public class RequestConverters { return request; } + public static Request indexCreate(org.elasticsearch.client.indices.CreateIndexRequest createIndexRequest) { + String endpoint = RequestConverters.endpoint(new String[]{createIndexRequest.index()}); + Request request = new Request(HttpMethod.PUT.name(), endpoint); + + Params parameters = new Params(request); + parameters.withTimeout(createIndexRequest.timeout()); + parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout()); + parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards(), ActiveShardCount.DEFAULT); + + request.setEntity(createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); + return request; + } + public static Request indexRefresh(RefreshRequest refreshRequest) { String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices(); @@ -800,6 +829,18 @@ public class RequestConverters { return request; } + public static Request putMapping(org.elasticsearch.client.indices.PutMappingRequest putMappingRequest) { + Request request = new Request(HttpMethod.PUT.name(), + RequestConverters.endpoint(putMappingRequest.indices(), "_mapping")); + + new RequestConverters.Params(request) // + .withTimeout(putMappingRequest.timeout()) // + .withMasterTimeout(putMappingRequest.masterNodeTimeout()) // + .withIncludeTypeName(false); + request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); + return request; + } + public static Request flushIndex(FlushRequest flushRequest) { String[] indices = flushRequest.indices() == null ? Strings.EMPTY_ARRAY : flushRequest.indices(); Request request = new Request(HttpMethod.POST.name(), RequestConverters.endpoint(indices, "_flush")); @@ -825,6 +866,19 @@ public class RequestConverters { return request; } + public static Request getMapping(org.elasticsearch.client.indices.GetMappingsRequest getMappingsRequest) { + String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); + + Request request = new Request(HttpMethod.GET.name(), RequestConverters.endpoint(indices, "_mapping")); + + RequestConverters.Params parameters = new RequestConverters.Params(request); + parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); + parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); + parameters.withLocal(getMappingsRequest.local()); + parameters.withIncludeTypeName(false); + return request; + } + public static Request getSettings(GetSettingsRequest getSettingsRequest) { String[] indices = getSettingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.indices(); String[] names = getSettingsRequest.names() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.names(); diff --git a/src/test/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClientIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClientIntegrationTests.java index 0aa6d93fc..fea6d3395 100644 --- a/src/test/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClientIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/client/reactive/ReactiveElasticsearchClientIntegrationTests.java @@ -18,6 +18,10 @@ package org.springframework.data.elasticsearch.client.reactive; import static org.assertj.core.api.Assertions.*; import lombok.SneakyThrows; +import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.client.indices.GetIndexRequest; +import org.elasticsearch.client.indices.GetMappingsRequest; +import org.elasticsearch.common.xcontent.XContentType; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -583,6 +587,28 @@ public class ReactiveElasticsearchClientIntegrationTests { .verifyComplete(); } + @Test // #1658 + public void indexExistsShouldReturnTrueIfExists() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + client.indices().existsIndex(new GetIndexRequest(INDEX_I)) // + .as(StepVerifier::create) // + .expectNext(true) // + .verifyComplete(); + } + + @Test // #1658 + public void indexExistsShouldReturnFalseIfNotExists() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + client.indices().existsIndex(new GetIndexRequest(INDEX_II)) // + .as(StepVerifier::create) // + .expectNext(false) // + .verifyComplete(); + } + @Test // DATAES-569, DATAES-678 public void createIndex() { @@ -607,6 +633,55 @@ public class ReactiveElasticsearchClientIntegrationTests { .verifyError(ElasticsearchStatusException.class); } + @Test // #1658 + public void createIndex_() { + + client.indices().createIndex(new CreateIndexRequest(INDEX_I)) + .as(StepVerifier::create) + .expectNext(true) + .verifyComplete(); + + operations.indexOps(IndexCoordinates.of(INDEX_I)).exists() // + .as(StepVerifier::create) // + .expectNext(true) // + .verifyComplete(); + } + + @Test // #1658 + public void createExistingIndexErrors_() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + client.indices().createIndex(new CreateIndexRequest(INDEX_I)) // + .as(StepVerifier::create) // + .verifyError(ElasticsearchStatusException.class); + } + + @Test // #1658 + public void getIndex() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + client.indices().getIndex(new GetIndexRequest(INDEX_I)) + .as(StepVerifier::create) + .consumeNextWith(it -> { + assertThat(it.getIndices().length).isOne(); + assertThat(it.getIndices()[0]).isEqualTo(INDEX_I); + }) + .verifyComplete(); + } + + @Test // #1658 + public void getIndexError() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + client.indices().getIndex(new GetIndexRequest(INDEX_II)) + .as(StepVerifier::create) + .verifyError(ElasticsearchStatusException.class); + } + + @Test // DATAES-569, DATAES-678 public void deleteExistingIndex() { @@ -686,6 +761,82 @@ public class ReactiveElasticsearchClientIntegrationTests { .verifyError(ElasticsearchStatusException.class); } + @Test // #1640 + void putMapping() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + Map jsonMap = Collections.singletonMap("properties", + Collections.singletonMap("message", Collections.singletonMap("type", "text"))); + + org.elasticsearch.client.indices.PutMappingRequest putMappingRequest = + new org.elasticsearch.client.indices.PutMappingRequest(INDEX_I).source(jsonMap); + + client.indices().putMapping(putMappingRequest) // + .as(StepVerifier::create) // + .expectNext(true) // + .verifyComplete(); + } + + @Test // #1640 + void putMappingError() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + Map jsonMap = Collections.singletonMap("properties", + Collections.singletonMap("message", Collections.singletonMap("type", "text"))); + + org.elasticsearch.client.indices.PutMappingRequest putMappingRequest = + new org.elasticsearch.client.indices.PutMappingRequest(INDEX_II).source(jsonMap); + + client.indices().putMapping(putMappingRequest) // + .as(StepVerifier::create) // + .verifyError(ElasticsearchStatusException.class); + } + + @Test // #1640 + void getMapping() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + Map jsonMap = Collections.singletonMap("properties", + Collections.singletonMap("message", Collections.singletonMap("type", "text"))); + + org.elasticsearch.client.indices.PutMappingRequest putMappingRequest = + new org.elasticsearch.client.indices.PutMappingRequest(INDEX_I).source(jsonMap); + + client.indices().putMapping(putMappingRequest).block(); + + final GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(INDEX_I); + + client.indices().getMapping(getMappingsRequest) // + .as(StepVerifier::create) // + .consumeNextWith(it -> { + assertThat(it.mappings().get(INDEX_I).getSourceAsMap()).isEqualTo(jsonMap); + }) + .verifyComplete(); + } + + @Test // #1640 + void getMappingError() { + + operations.indexOps(IndexCoordinates.of(INDEX_I)).create().block(); + + Map jsonMap = Collections.singletonMap("properties", + Collections.singletonMap("message", Collections.singletonMap("type", "text"))); + + org.elasticsearch.client.indices.PutMappingRequest putMappingRequest = + new org.elasticsearch.client.indices.PutMappingRequest(INDEX_I).source(jsonMap); + + client.indices().putMapping(putMappingRequest).block(); + + final GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(INDEX_II); + + client.indices().getMapping(getMappingsRequest) // + .as(StepVerifier::create) // + .verifyError(ElasticsearchStatusException.class); + } + @Test // DATAES-569 public void updateMapping() {