Skip to content

Commit bf51de3

Browse files
authored
DATAES-753 - Reactive Elasticsearch repository: Bulk update fails on empty entity list.
Original PR: spring-projects#398
1 parent 6a4a748 commit bf51de3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ default <T> Mono<T> save(Mono<? extends T> entityPublisher, IndexCoordinates ind
8888

8989
/**
9090
* Index entities under the given {@literal type} in the given {@literal index}. If the {@literal index} is
91-
* {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}.
91+
* {@literal null} or empty the index name provided via entity metadata is used.
9292
*
9393
* @param entities must not be {@literal null}.
9494
* @param index the target index, must not be {@literal null}
@@ -104,7 +104,7 @@ default <T> Flux<T> saveAll(Iterable<T> entities, IndexCoordinates index) {
104104

105105
/**
106106
* Index entities under the given {@literal type} in the given {@literal index}. If the {@literal index} is
107-
* {@literal null} or empty the index name provided via entity metadata is used. Same for the {@literal type}.
107+
* {@literal null} or empty the index name provided via entity metadata is used.
108108
*
109109
* @param entities must not be {@literal null}.
110110
* @param index the target index, must not be {@literal null}
@@ -228,7 +228,7 @@ default <T> Mono<T> findById(String id, Class<T> entityType, IndexCoordinates in
228228
* @param entity must not be {@literal null}.
229229
* @return a {@link Mono} emitting the {@literal id} of the removed document.
230230
*/
231-
Mono<String> delete(Object entity);
231+
Mono<String> delete(Object entity);
232232

233233
/**
234234
* Delete the given entity extracting index and type from entity metadata.
@@ -237,7 +237,7 @@ default <T> Mono<T> findById(String id, Class<T> entityType, IndexCoordinates in
237237
* @param index the target index, must not be {@literal null}
238238
* @return a {@link Mono} emitting the {@literal id} of the removed document.
239239
*/
240-
Mono<String> delete(Object entity, IndexCoordinates index);
240+
Mono<String> delete(Object entity, IndexCoordinates index);
241241

242242
/**
243243
* Delete the entity with given {@literal id}.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public <T> Flux<T> saveAll(Mono<? extends Collection<? extends T>> entities, Ind
160160
List<AdaptibleEntity<? extends T>> adaptibleEntities = entityList.stream() //
161161
.map(e -> operations.forEntity(e, converter.getConversionService())) //
162162
.collect(Collectors.toList());
163+
164+
if (adaptibleEntities.isEmpty()) {
165+
return Flux.empty();
166+
}
167+
163168
Iterator<AdaptibleEntity<? extends T>> iterator = adaptibleEntities.iterator();
164169
List<IndexQuery> indexRequests = adaptibleEntities.stream() //
165170
.map(e -> getIndexQuery(e.getBean(), e)) //
@@ -366,7 +371,7 @@ protected Mono<GetResult> doGet(GetRequest request) {
366371
* @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(Object, String, String)
367372
*/
368373
@Override
369-
public Mono<String> delete(Object entity, IndexCoordinates index) {
374+
public Mono<String> delete(Object entity, IndexCoordinates index) {
370375

371376
Entity<?> elasticsearchEntity = operations.forEntity(entity);
372377

src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,13 @@ void shouldSaveAll() {
811811
.verifyComplete();
812812
}
813813

814+
@Test // DATAES-753
815+
void shouldReturnEmptyFluxOnSaveAllWithEmptyInput() {
816+
template.saveAll(Collections.emptyList(), IndexCoordinates.of(DEFAULT_INDEX)) //
817+
.as(StepVerifier::create) //
818+
.verifyComplete();
819+
}
820+
814821
@Data
815822
@Document(indexName = "marvel")
816823
static class Person {

0 commit comments

Comments
 (0)