Search in sources :

Example 1 with ReindexResponse

use of org.springframework.data.elasticsearch.core.reindex.ReindexResponse in project spring-data-elasticsearch by spring-projects.

the class ElasticsearchTemplateTests method shouldWorkReindexForExistingIndex.

// #1529
@Test
void shouldWorkReindexForExistingIndex() {
    String sourceIndexName = indexNameProvider.indexName();
    String documentId = nextIdAsString();
    SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("abc").build();
    operations.save(sampleEntity);
    indexNameProvider.increment();
    String destIndexName = indexNameProvider.indexName();
    operations.indexOps(IndexCoordinates.of(destIndexName)).create();
    final ReindexRequest reindexRequest = ReindexRequest.builder(IndexCoordinates.of(sourceIndexName), IndexCoordinates.of(destIndexName)).withRefresh(true).build();
    final ReindexResponse reindex = operations.reindex(reindexRequest);
    NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
    assertThat(reindex.getTotal()).isEqualTo(1);
    assertThat(operations.count(searchQuery, IndexCoordinates.of(destIndexName))).isEqualTo(1);
}
Also used : ReindexResponse(org.springframework.data.elasticsearch.core.reindex.ReindexResponse) ReindexRequest(org.springframework.data.elasticsearch.core.reindex.ReindexRequest) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

Test (org.junit.jupiter.api.Test)1 ReindexRequest (org.springframework.data.elasticsearch.core.reindex.ReindexRequest)1 ReindexResponse (org.springframework.data.elasticsearch.core.reindex.ReindexResponse)1 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)1