mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-832 - findAllById repository method returns iterable with null elements for not found ids.
This commit is contained in:
parent
b439acac16
commit
49f1516b9e
@ -17,9 +17,9 @@ package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -152,10 +152,23 @@ public class SimpleElasticsearchRepository<T, ID> implements ElasticsearchReposi
|
||||
|
||||
@Override
|
||||
public Iterable<T> findAllById(Iterable<ID> ids) {
|
||||
|
||||
Assert.notNull(ids, "ids can't be null.");
|
||||
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder().withIds(stringIdsRepresentation(ids)).build();
|
||||
return execute(operations1 -> operations1.multiGet(query, entityClass, getIndexCoordinates())).stream()
|
||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||
List<T> result = new ArrayList<>();
|
||||
List<T> multiGetEntities = execute(operations -> operations.multiGet(query, entityClass, getIndexCoordinates()));
|
||||
|
||||
if (multiGetEntities != null) {
|
||||
multiGetEntities.forEach(entity -> {
|
||||
|
||||
if (entity != null) {
|
||||
result.add(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user