Skip to content

Commit 8c63f3e

Browse files
committed
DATAES-82 - findAll(Iterable<ID> ids) does not work with Collections
terms query does not support iterable, converted Iterable to Collection
1 parent ad0409c commit 8c63f3e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727

2828
import org.elasticsearch.ElasticsearchException;
29+
import org.elasticsearch.common.collect.Lists;
2930
import org.elasticsearch.index.query.QueryBuilder;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
@@ -118,7 +119,9 @@ public Iterable<T> findAll(Sort sort) {
118119

119120
@Override
120121
public Iterable<T> findAll(Iterable<ID> ids) {
121-
SearchQuery query = new NativeSearchQueryBuilder().withQuery(inQuery(entityInformation.getIdAttribute(), ids))
122+
Assert.notNull(ids, "ids can't be null.");
123+
SearchQuery query = new NativeSearchQueryBuilder()
124+
.withQuery(inQuery(entityInformation.getIdAttribute(), Lists.newArrayList(ids)))
122125
.build();
123126
return elasticsearchOperations.queryForPage(query, getEntityClass());
124127
}

src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,8 +24,8 @@
2424
import java.util.Arrays;
2525
import java.util.List;
2626

27+
import org.elasticsearch.common.collect.Lists;
2728
import org.junit.Before;
28-
import org.junit.Ignore;
2929
import org.junit.Test;
3030
import org.junit.runner.RunWith;
3131
import org.springframework.beans.factory.annotation.Autowired;
@@ -204,10 +204,11 @@ public void shouldSearchDocumentsGivenElasticsearchQuery() {
204204
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
205205
}
206206

207+
/*
208+
DATAES-82
209+
*/
207210
@Test
208-
@Ignore
209211
public void shouldFindAllByIdQuery() {
210-
// todo : find solution for findAll(Iterable<Ids> ids)
211212
// given
212213
String documentId = randomNumeric(5);
213214
SampleEntity sampleEntity = new SampleEntity();
@@ -228,6 +229,8 @@ public void shouldFindAllByIdQuery() {
228229

229230
// then
230231
assertNotNull("sample entities cant be null..", sampleEntities);
232+
List<SampleEntity> entities = Lists.newArrayList(sampleEntities);
233+
assertThat(entities.size(), is(2));
231234
}
232235

233236
@Test

0 commit comments

Comments
 (0)