mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 19:42:10 +00:00
findAllById returns all requested documents.
Original Pull Request #2421 Closes #2417 (cherry picked from commit 28489ffee8f405d8f5d2000bb40161d61b21485d) (cherry picked from commit 6551a80ccc503b20c09eae2ebc3ac33dafcb3c34)
This commit is contained in:
parent
b896694d3a
commit
87540bcabc
@ -202,29 +202,27 @@ abstract class ElasticsearchRepositoryIntegrationTests {
|
|||||||
assertThat(entityFromElasticSearch).isNotPresent();
|
assertThat(entityFromElasticSearch).isNotPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-82
|
@Test // DATAES-82, #2417
|
||||||
void shouldFindAllByIdQuery() {
|
void shouldFindAllByIdQuery() {
|
||||||
|
|
||||||
// given
|
// create more than 10 documents to see that the number of input ids is set as requested size
|
||||||
|
int numEntities = 20;
|
||||||
|
List<String> ids = new ArrayList<>(numEntities);
|
||||||
|
List<SampleEntity> entities = new ArrayList<>(numEntities);
|
||||||
|
for (int i = 0; i < numEntities; i++) {
|
||||||
String documentId = nextIdAsString();
|
String documentId = nextIdAsString();
|
||||||
|
ids.add(documentId);
|
||||||
SampleEntity sampleEntity = new SampleEntity();
|
SampleEntity sampleEntity = new SampleEntity();
|
||||||
sampleEntity.setId(documentId);
|
sampleEntity.setId(documentId);
|
||||||
sampleEntity.setMessage("hello world.");
|
sampleEntity.setMessage("hello world.");
|
||||||
sampleEntity.setVersion(System.currentTimeMillis());
|
sampleEntity.setVersion(System.currentTimeMillis());
|
||||||
repository.save(sampleEntity);
|
entities.add(sampleEntity);
|
||||||
|
}
|
||||||
|
repository.saveAll(entities);
|
||||||
|
|
||||||
String documentId2 = nextIdAsString();
|
Iterable<SampleEntity> sampleEntities = repository.findAllById(ids);
|
||||||
SampleEntity sampleEntity2 = new SampleEntity();
|
|
||||||
sampleEntity2.setId(documentId2);
|
|
||||||
sampleEntity2.setMessage("hello world.");
|
|
||||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
|
||||||
repository.save(sampleEntity2);
|
|
||||||
|
|
||||||
// when
|
assertThat(sampleEntities).isNotNull().hasSize(numEntities);
|
||||||
Iterable<SampleEntity> sampleEntities = repository.findAllById(Arrays.asList(documentId, documentId2));
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -17,11 +17,13 @@ package org.springframework.data.elasticsearch.repository.support;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.springframework.data.elasticsearch.core.query.Query.*;
|
import static org.springframework.data.elasticsearch.core.query.Query.*;
|
||||||
|
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||||
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.test.StepVerifier;
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -63,13 +65,10 @@ import org.springframework.lang.Nullable;
|
|||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired ReactiveElasticsearchOperations operations;
|
||||||
ReactiveElasticsearchOperations operations;
|
@Autowired ReactiveSampleEntityRepository repository;
|
||||||
@Autowired
|
|
||||||
ReactiveSampleEntityRepository repository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired private IndexNameProvider indexNameProvider;
|
||||||
private IndexNameProvider indexNameProvider;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void before() {
|
void before() {
|
||||||
@ -172,19 +171,27 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
|||||||
repository.findAllById(Arrays.asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete();
|
repository.findAllById(Arrays.asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test // DATAES-519, #2417
|
||||||
// DATAES-519
|
|
||||||
void findAllByIdShouldRetrieveMatchingDocuments() {
|
void findAllByIdShouldRetrieveMatchingDocuments() {
|
||||||
|
|
||||||
bulkIndex(new SampleEntity("id-one"), //
|
// create more than 10 documents to see that the number of input ids is set as requested size
|
||||||
new SampleEntity("id-two"), //
|
int numEntities = 20;
|
||||||
new SampleEntity("id-three")) //
|
List<String> ids = new ArrayList<>(numEntities);
|
||||||
.block();
|
List<SampleEntity> entities = new ArrayList<>(numEntities);
|
||||||
|
for (int i = 0; i < numEntities; i++) {
|
||||||
|
String documentId = nextIdAsString();
|
||||||
|
ids.add(documentId);
|
||||||
|
SampleEntity sampleEntity = new SampleEntity();
|
||||||
|
sampleEntity.setId(documentId);
|
||||||
|
sampleEntity.setMessage("hello world.");
|
||||||
|
sampleEntity.setVersion(System.currentTimeMillis());
|
||||||
|
entities.add(sampleEntity);
|
||||||
|
}
|
||||||
|
repository.saveAll(entities).blockLast();
|
||||||
|
|
||||||
repository.findAllById(Arrays.asList("id-one", "id-two")) //
|
repository.findAllById(ids) //
|
||||||
.as(StepVerifier::create)//
|
.as(StepVerifier::create)//
|
||||||
.expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) //
|
.expectNextCount(numEntities) //
|
||||||
.expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) //
|
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,8 +429,7 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
|||||||
bulkIndex(new SampleEntity("id-one"), toBeDeleted) //
|
bulkIndex(new SampleEntity("id-one"), toBeDeleted) //
|
||||||
.block();
|
.block();
|
||||||
|
|
||||||
repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create)
|
repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete();
|
||||||
.verifyComplete();
|
|
||||||
|
|
||||||
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
|
assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse();
|
||||||
}
|
}
|
||||||
@ -670,8 +676,7 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
|||||||
new SampleEntity("id-five", "message5", 5)) //
|
new SampleEntity("id-five", "message5", 5)) //
|
||||||
.block();
|
.block();
|
||||||
|
|
||||||
repository.findAllViaAnnotatedQueryByMessageInAndRatesIn(Arrays.asList("message5", "message3"), Arrays.asList(2,
|
repository.findAllViaAnnotatedQueryByMessageInAndRatesIn(Arrays.asList("message5", "message3"), Arrays.asList(2, 3)) //
|
||||||
3)) //
|
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-three")) //
|
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo("id-three")) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
@ -732,24 +737,17 @@ abstract class SimpleReactiveElasticsearchRepositoryIntegrationTests {
|
|||||||
@Document(indexName = "#{@indexNameProvider.indexName()}")
|
@Document(indexName = "#{@indexNameProvider.indexName()}")
|
||||||
static class SampleEntity {
|
static class SampleEntity {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Id
|
@Id private String id;
|
||||||
private String id;
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Field(type = FieldType.Text, store = true, fielddata = true)
|
@Field(type = FieldType.Text, store = true, fielddata = true) private String type;
|
||||||
private String type;
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Field(type = FieldType.Text, store = true, fielddata = true)
|
@Field(type = FieldType.Text, store = true, fielddata = true) private String message;
|
||||||
private String message;
|
@Nullable private int rate;
|
||||||
|
@Nullable private boolean available;
|
||||||
@Nullable
|
@Nullable
|
||||||
private int rate;
|
@Version private Long version;
|
||||||
@Nullable
|
|
||||||
private boolean available;
|
|
||||||
@Nullable
|
|
||||||
@Version
|
|
||||||
private Long version;
|
|
||||||
|
|
||||||
public SampleEntity() {
|
public SampleEntity() {}
|
||||||
}
|
|
||||||
|
|
||||||
public SampleEntity(@Nullable String id) {
|
public SampleEntity(@Nullable String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user