|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.repository.support;
|
17 | 17 |
|
18 |
| -import static org.elasticsearch.index.query.QueryBuilders.*; |
| 18 | +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; |
19 | 19 |
|
20 | 20 | import java.io.Serializable;
|
21 | 21 | import java.lang.reflect.ParameterizedType;
|
|
26 | 26 | import java.util.List;
|
27 | 27 |
|
28 | 28 | import org.elasticsearch.ElasticsearchException;
|
29 |
| -import org.elasticsearch.common.collect.Lists; |
30 | 29 | import org.elasticsearch.index.query.QueryBuilder;
|
31 | 30 | import org.slf4j.Logger;
|
32 | 31 | import org.slf4j.LoggerFactory;
|
33 | 32 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
34 |
| -import org.springframework.data.domain.*; |
| 33 | +import org.springframework.data.domain.Page; |
| 34 | +import org.springframework.data.domain.PageImpl; |
| 35 | +import org.springframework.data.domain.PageRequest; |
| 36 | +import org.springframework.data.domain.Pageable; |
| 37 | +import org.springframework.data.domain.Sort; |
35 | 38 | import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
36 | 39 | import org.springframework.data.elasticsearch.core.FacetedPage;
|
37 |
| -import org.springframework.data.elasticsearch.core.query.*; |
| 40 | +import org.springframework.data.elasticsearch.core.query.DeleteQuery; |
| 41 | +import org.springframework.data.elasticsearch.core.query.GetQuery; |
| 42 | +import org.springframework.data.elasticsearch.core.query.IndexQuery; |
| 43 | +import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; |
| 44 | +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; |
| 45 | +import org.springframework.data.elasticsearch.core.query.SearchQuery; |
38 | 46 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
39 | 47 | import org.springframework.util.Assert;
|
40 | 48 |
|
|
45 | 53 | * @author Rizwan Idrees
|
46 | 54 | * @author Mohsin Husen
|
47 | 55 | * @author Ryan Henszey
|
| 56 | + * @author Kevin Leturc |
48 | 57 | */
|
49 | 58 | public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
50 | 59 | ElasticsearchRepository<T, ID> {
|
@@ -121,9 +130,9 @@ public Iterable<T> findAll(Sort sort) {
|
121 | 130 | public Iterable<T> findAll(Iterable<ID> ids) {
|
122 | 131 | Assert.notNull(ids, "ids can't be null.");
|
123 | 132 | SearchQuery query = new NativeSearchQueryBuilder()
|
124 |
| - .withQuery(inQuery(entityInformation.getIdAttribute(), Lists.newArrayList(ids))) |
| 133 | + .withIds(stringIdsRepresentation(ids)) |
125 | 134 | .build();
|
126 |
| - return elasticsearchOperations.queryForPage(query, getEntityClass()); |
| 135 | + return elasticsearchOperations.multiGet(query, getEntityClass()); |
127 | 136 | }
|
128 | 137 |
|
129 | 138 | @Override
|
@@ -302,6 +311,15 @@ protected ID extractIdFromBean(T entity) {
|
302 | 311 | return null;
|
303 | 312 | }
|
304 | 313 |
|
| 314 | + private List<String> stringIdsRepresentation(Iterable<ID> ids) { |
| 315 | + Assert.notNull(ids, "ids can't be null."); |
| 316 | + List<String> stringIds = new ArrayList<String>(); |
| 317 | + for (ID id : ids) { |
| 318 | + stringIds.add(stringIdRepresentation(id)); |
| 319 | + } |
| 320 | + return stringIds; |
| 321 | + } |
| 322 | + |
305 | 323 | protected abstract String stringIdRepresentation(ID id);
|
306 | 324 |
|
307 | 325 | private Long extractVersionFromBean(T entity) {
|
|
0 commit comments