From bf51de3805b64bb0817c037ff64c7c6c113b6277 Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Wed, 26 Feb 2020 21:50:42 +0100 Subject: [PATCH] DATAES-753 - Reactive Elasticsearch repository: Bulk update fails on empty entity list. Original PR: #398 --- .../elasticsearch/core/ReactiveDocumentOperations.java | 8 ++++---- .../elasticsearch/core/ReactiveElasticsearchTemplate.java | 7 ++++++- .../core/ReactiveElasticsearchTemplateTests.java | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java index 955a122bb..66f1eebee 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveDocumentOperations.java @@ -88,7 +88,7 @@ public interface ReactiveDocumentOperations { /** * Index entities under the given {@literal type} in the given {@literal index}. If the {@literal index} is - * {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}. + * {@literal null} or empty the index name provided via entity metadata is used. * * @param entities must not be {@literal null}. * @param index the target index, must not be {@literal null} @@ -104,7 +104,7 @@ public interface ReactiveDocumentOperations { /** * Index entities under the given {@literal type} in the given {@literal index}. If the {@literal index} is - * {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}. + * {@literal null} or empty the index name provided via entity metadata is used. * * @param entities must not be {@literal null}. * @param index the target index, must not be {@literal null} @@ -228,7 +228,7 @@ public interface ReactiveDocumentOperations { * @param entity must not be {@literal null}. * @return a {@link Mono} emitting the {@literal id} of the removed document. */ - Mono delete(Object entity); + Mono delete(Object entity); /** * Delete the given entity extracting index and type from entity metadata. @@ -237,7 +237,7 @@ public interface ReactiveDocumentOperations { * @param index the target index, must not be {@literal null} * @return a {@link Mono} emitting the {@literal id} of the removed document. */ - Mono delete(Object entity, IndexCoordinates index); + Mono delete(Object entity, IndexCoordinates index); /** * Delete the entity with given {@literal id}. diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java index ada81c511..32123cda2 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplate.java @@ -160,6 +160,11 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera List> adaptibleEntities = entityList.stream() // .map(e -> operations.forEntity(e, converter.getConversionService())) // .collect(Collectors.toList()); + + if (adaptibleEntities.isEmpty()) { + return Flux.empty(); + } + Iterator> iterator = adaptibleEntities.iterator(); List indexRequests = adaptibleEntities.stream() // .map(e -> getIndexQuery(e.getBean(), e)) // @@ -366,7 +371,7 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera * @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(Object, String, String) */ @Override - public Mono delete(Object entity, IndexCoordinates index) { + public Mono delete(Object entity, IndexCoordinates index) { Entity elasticsearchEntity = operations.forEntity(entity); diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java index 6312888d5..02d0e60c2 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java @@ -811,6 +811,13 @@ public class ReactiveElasticsearchTemplateTests { .verifyComplete(); } + @Test // DATAES-753 + void shouldReturnEmptyFluxOnSaveAllWithEmptyInput() { + template.saveAll(Collections.emptyList(), IndexCoordinates.of(DEFAULT_INDEX)) // + .as(StepVerifier::create) // + .verifyComplete(); + } + @Data @Document(indexName = "marvel") static class Person {