Search in sources :

Example 31 with IndexCoordinates

use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.

the class ElasticsearchTemplateTests method shouldDeleteIndexForSpecifiedIndexName.

// DATAES-72
@Test
public void shouldDeleteIndexForSpecifiedIndexName() {
    // given
    String indexName = "some-random-index";
    IndexCoordinates index = IndexCoordinates.of(indexName);
    operations.indexOps(index).create();
    operations.indexOps(index).refresh();
    // when
    operations.indexOps(index).delete();
    // then
    assertThat(operations.indexOps(index).exists()).isFalse();
}
Also used : IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 32 with IndexCoordinates

use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateIntegrationTests method insertWithExplicitIndexNameShouldOverwriteMetadata.

// DATAES-504
@Test
public void insertWithExplicitIndexNameShouldOverwriteMetadata() {
    String defaultIndexName = indexNameProvider.indexName();
    String alternateIndexName = defaultIndexName + "-alt";
    SampleEntity sampleEntity = randomEntity("in another index");
    IndexCoordinates alternateIndex = IndexCoordinates.of(alternateIndexName);
    // 
    operations.save(sampleEntity, alternateIndex).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    assertThat(documentWithIdExistsInIndex(sampleEntity.getId(), defaultIndexName).block()).isFalse();
    assertThat(documentWithIdExistsInIndex(sampleEntity.getId(), alternateIndexName).block()).isTrue();
}
Also used : StepVerifier(reactor.test.StepVerifier) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 33 with IndexCoordinates

use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateIntegrationTests method shouldDeleteAcrossIndex.

// DATAES-547
@Test
public void shouldDeleteAcrossIndex() {
    String indexPrefix = "rx-template-test-index";
    IndexCoordinates thisIndex = IndexCoordinates.of(indexPrefix + "-this");
    IndexCoordinates thatIndex = IndexCoordinates.of(indexPrefix + "-that");
    // 
    operations.save(randomEntity("test"), thisIndex).then(// 
    operations.save(randomEntity("test"), thatIndex)).then().as(// 
    StepVerifier::create).verifyComplete();
    operations.indexOps(thisIndex).refresh().then(operations.indexOps(thatIndex).refresh()).block();
    NativeSearchQuery searchQuery = // 
    new NativeSearchQueryBuilder().withQuery(// 
    termQuery("message", "test")).build();
    // 
    operations.delete(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')).map(// 
    ByQueryResponse::getDeleted).as(// 
    StepVerifier::create).expectNext(// 
    2L).verifyComplete();
    operations.indexOps(thisIndex).delete().then(operations.indexOps(thatIndex).delete()).block();
}
Also used : StepVerifier(reactor.test.StepVerifier) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 34 with IndexCoordinates

use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateIntegrationTests method getByIdWithExplicitIndexNameShouldOverwriteMetadata.

// DATAES-504
@Test
public void getByIdWithExplicitIndexNameShouldOverwriteMetadata() {
    SampleEntity sampleEntity = randomEntity("some message");
    IndexCoordinates defaultIndex = IndexCoordinates.of(indexNameProvider.indexName());
    IndexCoordinates alternateIndex = IndexCoordinates.of(indexNameProvider.indexName() + "-alt");
    // 
    operations.save(sampleEntity, alternateIndex).then(// 
    operations.indexOps(defaultIndex).refresh()).then(// 
    operations.indexOps(alternateIndex).refresh()).block();
    // 
    operations.get(sampleEntity.getId(), SampleEntity.class, defaultIndex).as(// 
    StepVerifier::create).verifyComplete();
    // 
    operations.get(sampleEntity.getId(), SampleEntity.class, alternateIndex).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
}
Also used : StepVerifier(reactor.test.StepVerifier) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 35 with IndexCoordinates

use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplateIntegrationTests method shouldDeleteAcrossIndexWhenNoMatchingDataPresent.

// DATAES-547
@Test
public void shouldDeleteAcrossIndexWhenNoMatchingDataPresent() {
    String indexPrefix = "rx-template-test-index";
    IndexCoordinates thisIndex = IndexCoordinates.of(indexPrefix + "-this");
    IndexCoordinates thatIndex = IndexCoordinates.of(indexPrefix + "-that");
    // 
    operations.save(randomEntity("positive"), thisIndex).then(// 
    operations.save(randomEntity("positive"), thatIndex)).then().as(// 
    StepVerifier::create).verifyComplete();
    operations.indexOps(thisIndex).refresh().then(operations.indexOps(thatIndex).refresh()).block();
    NativeSearchQuery searchQuery = // 
    new NativeSearchQueryBuilder().withQuery(// 
    termQuery("message", "negative")).build();
    // 
    operations.delete(searchQuery, SampleEntity.class, IndexCoordinates.of(indexPrefix + '*')).map(// 
    ByQueryResponse::getDeleted).as(// 
    StepVerifier::create).expectNext(// 
    0L).verifyComplete();
    operations.indexOps(thisIndex).delete().then(operations.indexOps(thatIndex).delete()).block();
}
Also used : StepVerifier(reactor.test.StepVerifier) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)50 Test (org.junit.jupiter.api.Test)27 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)27 IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)20 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)16 Query (org.springframework.data.elasticsearch.core.query.Query)16 ArrayList (java.util.ArrayList)15 Nullable (org.springframework.lang.Nullable)11 HashMap (java.util.HashMap)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)10 Map (java.util.Map)9 SearchRequest (org.elasticsearch.action.search.SearchRequest)9 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)9 Log (org.apache.commons.logging.Log)8 LogFactory (org.apache.commons.logging.LogFactory)8 Version (org.elasticsearch.Version)8 DocWriteResponse (org.elasticsearch.action.DocWriteResponse)8 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)8