DATAES-753 - Reactive Elasticsearch repository: Bulk update fails on empty entity list.

Original PR: #398
This commit is contained in:
Peter-Josef Meisch 2020-02-26 21:50:42 +01:00 committed by GitHub
parent 6a4a7483aa
commit bf51de3805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -88,7 +88,7 @@ public interface ReactiveDocumentOperations {
/** /**
* Index entities under the given {@literal type} in the given {@literal index}. If the {@literal index} is * 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 entities must not be {@literal null}.
* @param index the target index, 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 * 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 entities must not be {@literal null}.
* @param index the target index, 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}. * @param entity must not be {@literal null}.
* @return a {@link Mono} emitting the {@literal id} of the removed document. * @return a {@link Mono} emitting the {@literal id} of the removed document.
*/ */
Mono<String> delete(Object entity); Mono<String> delete(Object entity);
/** /**
* Delete the given entity extracting index and type from entity metadata. * 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} * @param index the target index, must not be {@literal null}
* @return a {@link Mono} emitting the {@literal id} of the removed document. * @return a {@link Mono} emitting the {@literal id} of the removed document.
*/ */
Mono<String> delete(Object entity, IndexCoordinates index); Mono<String> delete(Object entity, IndexCoordinates index);
/** /**
* Delete the entity with given {@literal id}. * Delete the entity with given {@literal id}.

View File

@ -160,6 +160,11 @@ public class ReactiveElasticsearchTemplate implements ReactiveElasticsearchOpera
List<AdaptibleEntity<? extends T>> adaptibleEntities = entityList.stream() // List<AdaptibleEntity<? extends T>> adaptibleEntities = entityList.stream() //
.map(e -> operations.forEntity(e, converter.getConversionService())) // .map(e -> operations.forEntity(e, converter.getConversionService())) //
.collect(Collectors.toList()); .collect(Collectors.toList());
if (adaptibleEntities.isEmpty()) {
return Flux.empty();
}
Iterator<AdaptibleEntity<? extends T>> iterator = adaptibleEntities.iterator(); Iterator<AdaptibleEntity<? extends T>> iterator = adaptibleEntities.iterator();
List<IndexQuery> indexRequests = adaptibleEntities.stream() // List<IndexQuery> indexRequests = adaptibleEntities.stream() //
.map(e -> getIndexQuery(e.getBean(), e)) // .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) * @see org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations#delete(Object, String, String)
*/ */
@Override @Override
public Mono<String> delete(Object entity, IndexCoordinates index) { public Mono<String> delete(Object entity, IndexCoordinates index) {
Entity<?> elasticsearchEntity = operations.forEntity(entity); Entity<?> elasticsearchEntity = operations.forEntity(entity);

View File

@ -811,6 +811,13 @@ public class ReactiveElasticsearchTemplateTests {
.verifyComplete(); .verifyComplete();
} }
@Test // DATAES-753
void shouldReturnEmptyFluxOnSaveAllWithEmptyInput() {
template.saveAll(Collections.emptyList(), IndexCoordinates.of(DEFAULT_INDEX)) //
.as(StepVerifier::create) //
.verifyComplete();
}
@Data @Data
@Document(indexName = "marvel") @Document(indexName = "marvel")
static class Person { static class Person {