Skip to content

Commit 49f1516

Browse files
committed
DATAES-832 - findAllById repository method returns iterable with null elements for not found ids.
1 parent b439aca commit 49f1516

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import static org.elasticsearch.index.query.QueryBuilders.*;
1919

20+
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.List;
22-
import java.util.Objects;
2323
import java.util.Optional;
2424
import java.util.stream.Collectors;
2525

@@ -152,10 +152,23 @@ public Iterable<T> findAll(Sort sort) {
152152

153153
@Override
154154
public Iterable<T> findAllById(Iterable<ID> ids) {
155+
155156
Assert.notNull(ids, "ids can't be null.");
157+
156158
NativeSearchQuery query = new NativeSearchQueryBuilder().withIds(stringIdsRepresentation(ids)).build();
157-
return execute(operations1 -> operations1.multiGet(query, entityClass, getIndexCoordinates())).stream()
158-
.filter(Objects::nonNull).collect(Collectors.toList());
159+
List<T> result = new ArrayList<>();
160+
List<T> multiGetEntities = execute(operations -> operations.multiGet(query, entityClass, getIndexCoordinates()));
161+
162+
if (multiGetEntities != null) {
163+
multiGetEntities.forEach(entity -> {
164+
165+
if (entity != null) {
166+
result.add(entity);
167+
}
168+
});
169+
}
170+
171+
return result;
159172
}
160173

161174
@Override

0 commit comments

Comments
 (0)