use of org.springframework.data.elasticsearch.core.index.AliasActions in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateIntegrationTests method shouldReturnInformationListOfAllIndices.
// #1646, #1718
@Test
@DisplayName("should return a list of info for specific index")
void shouldReturnInformationListOfAllIndices() {
String indexName = indexNameProvider.indexName();
String aliasName = indexName + "-alias";
ReactiveIndexOperations indexOps = operations.indexOps(EntityWithSettingsAndMappingsReactive.class);
// beforeEach uses SampleEntity, so recreate the index here
indexOps.delete().then(indexOps.createWithMapping()).block();
AliasActionParameters parameters = AliasActionParameters.builder().withAliases(aliasName).withIndices(indexName).withIsHidden(false).withIsWriteIndex(false).withRouting("indexrouting").withSearchRouting("searchrouting").build();
indexOps.alias(new AliasActions(new AliasAction.Add(parameters))).block();
indexOps.getInformation().as(StepVerifier::create).consumeNextWith(indexInformation -> {
assertThat(indexInformation.getName()).isEqualTo(indexName);
assertThat(indexInformation.getSettings().get("index.number_of_shards")).isEqualTo("1");
assertThat(indexInformation.getSettings().get("index.number_of_replicas")).isEqualTo("0");
assertThat(indexInformation.getSettings().get("index.analysis.analyzer.emailAnalyzer.type")).isEqualTo("custom");
assertThat(indexInformation.getAliases()).hasSize(1);
AliasData aliasData = indexInformation.getAliases().get(0);
assertThat(aliasData.getAlias()).isEqualTo(aliasName);
assertThat(aliasData.isHidden()).isEqualTo(false);
assertThat(aliasData.isWriteIndex()).isEqualTo(false);
assertThat(aliasData.getIndexRouting()).isEqualTo("indexrouting");
assertThat(aliasData.getSearchRouting()).isEqualTo("searchrouting");
String expectedMappings = "{\"properties\":{\"email\":{\"type\":\"text\",\"analyzer\":\"emailAnalyzer\"}}}";
try {
JSONAssert.assertEquals(expectedMappings, indexInformation.getMapping().toJson(), false);
} catch (JSONException e) {
e.printStackTrace();
}
}).verifyComplete();
}
use of org.springframework.data.elasticsearch.core.index.AliasActions in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldCreateAlias.
// DATAES-864
@Test
void shouldCreateAlias() {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
AliasActions aliasActions = new AliasActions();
aliasActions.add(new AliasAction.Add(AliasActionParameters.builder().withIndices(indexOps.getIndexCoordinates().getIndexNames()).withAliases("aliasA", "aliasB").build()));
indexOps.create().flatMap(success -> {
if (success) {
return indexOps.alias(aliasActions);
} else {
return Mono.just(false);
}
}).as(StepVerifier::create).expectNext(true).verifyComplete();
}
use of org.springframework.data.elasticsearch.core.index.AliasActions in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldPutTemplate.
// DATAES-612
@Test
void shouldPutTemplate() {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
org.springframework.data.elasticsearch.core.document.Document mapping = indexOps.createMapping(TemplateClass.class).block();
Settings settings = indexOps.createSettings(TemplateClass.class).block();
AliasActions aliasActions = new AliasActions(new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias1", "alias2").build()));
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder("test-template", "log-*").withSettings(//
settings).withMappings(//
mapping).withAliasActions(//
aliasActions).withOrder(//
11).withVersion(//
42).build();
Boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
assertThat(acknowledged).isTrue();
}
use of org.springframework.data.elasticsearch.core.index.AliasActions in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldGetAliasData.
// DATAES-864
@Test
void shouldGetAliasData() {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
AliasActions aliasActions = new AliasActions();
aliasActions.add(new AliasAction.Add(AliasActionParameters.builder().withIndices(indexOps.getIndexCoordinates().getIndexNames()).withAliases("aliasA", "aliasB").build()));
assertThat(indexOps.create().block()).isTrue();
assertThat(indexOps.alias(aliasActions).block()).isTrue();
//
indexOps.getAliases("aliasA").as(//
StepVerifier::create).assertNext(aliasDatas -> {
//
Set<AliasData> aliasData = aliasDatas.get(indexOps.getIndexCoordinates().getIndexName());
assertThat(aliasData.stream().map(AliasData::getAlias)).containsExactly("aliasA");
}).verifyComplete();
}
Aggregations