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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations