Search in sources :

Example 6 with AliasActions

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) StepVerifier(reactor.test.StepVerifier) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) RestStatusException(org.springframework.data.elasticsearch.RestStatusException) Version(org.springframework.data.annotation.Version) Autowired(org.springframework.beans.factory.annotation.Autowired) Order(org.junit.jupiter.api.Order) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ParsedStringTerms(org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms) JSONException(org.json.JSONException) OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) ReindexRequest(org.springframework.data.elasticsearch.core.reindex.ReindexRequest) Long(java.lang.Long) Map(java.util.Map) Document(org.springframework.data.elasticsearch.annotations.Document) Assertions(org.assertj.core.api.Assertions) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) org.springframework.data.elasticsearch.core.query(org.springframework.data.elasticsearch.core.query) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) Explanation(org.springframework.data.elasticsearch.core.document.Explanation) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) FieldType(org.springframework.data.elasticsearch.annotations.FieldType) List(java.util.List) LocalDate(java.time.LocalDate) SortOrder(org.elasticsearch.search.sort.SortOrder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) IndexNameProvider(org.springframework.data.elasticsearch.utils.IndexNameProvider) Id(org.springframework.data.annotation.Id) IntStream(java.util.stream.IntStream) DataAccessException(org.springframework.dao.DataAccessException) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Field(org.springframework.data.elasticsearch.annotations.Field) AtomicReference(java.util.concurrent.atomic.AtomicReference) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) ReactiveElasticsearchRestTemplateConfiguration(org.springframework.data.elasticsearch.junit.jupiter.ReactiveElasticsearchRestTemplateConfiguration) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Mapping(org.springframework.data.elasticsearch.annotations.Mapping) Boolean(java.lang.Boolean) ConnectException(java.net.ConnectException) Aggregation(org.elasticsearch.search.aggregations.Aggregation) Nullable(org.springframework.lang.Nullable) Setting(org.springframework.data.elasticsearch.annotations.Setting) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters) Import(org.springframework.context.annotation.Import) Mono(reactor.core.publisher.Mono) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) ReactiveElasticsearchClient(org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient) DisplayName(org.junit.jupiter.api.DisplayName) DateTimeFormatter(java.time.format.DateTimeFormatter) Object(java.lang.Object) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters) JSONException(org.json.JSONException) StepVerifier(reactor.test.StepVerifier) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with AliasActions

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Settings(org.springframework.data.elasticsearch.core.index.Settings) Field(org.springframework.data.elasticsearch.annotations.Field) Autowired(org.springframework.beans.factory.annotation.Autowired) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) ReactiveElasticsearchRestTemplateConfiguration(org.springframework.data.elasticsearch.junit.jupiter.ReactiveElasticsearchRestTemplateConfiguration) Mapping(org.springframework.data.elasticsearch.annotations.Mapping) JSONException(org.json.JSONException) Map(java.util.Map) Document(org.springframework.data.elasticsearch.annotations.Document) Assertions(org.assertj.core.api.Assertions) Nullable(org.springframework.lang.Nullable) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) DeleteTemplateRequest(org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) Setting(org.springframework.data.elasticsearch.annotations.Setting) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters) Set(java.util.Set) Import(org.springframework.context.annotation.Import) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) DateFormat(org.springframework.data.elasticsearch.annotations.DateFormat) PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) AfterEach(org.junit.jupiter.api.AfterEach) FieldType(org.springframework.data.elasticsearch.annotations.FieldType) GetTemplateRequest(org.springframework.data.elasticsearch.core.index.GetTemplateRequest) LocalDate(java.time.LocalDate) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Id(org.springframework.data.annotation.Id) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) StepVerifier(reactor.test.StepVerifier) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 8 with AliasActions

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();
}
Also used : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) Settings(org.springframework.data.elasticsearch.core.index.Settings) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 9 with AliasActions

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Settings(org.springframework.data.elasticsearch.core.index.Settings) Field(org.springframework.data.elasticsearch.annotations.Field) Autowired(org.springframework.beans.factory.annotation.Autowired) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) ReactiveElasticsearchRestTemplateConfiguration(org.springframework.data.elasticsearch.junit.jupiter.ReactiveElasticsearchRestTemplateConfiguration) Mapping(org.springframework.data.elasticsearch.annotations.Mapping) JSONException(org.json.JSONException) Map(java.util.Map) Document(org.springframework.data.elasticsearch.annotations.Document) Assertions(org.assertj.core.api.Assertions) Nullable(org.springframework.lang.Nullable) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) DeleteTemplateRequest(org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) Setting(org.springframework.data.elasticsearch.annotations.Setting) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters) Set(java.util.Set) Import(org.springframework.context.annotation.Import) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) DateFormat(org.springframework.data.elasticsearch.annotations.DateFormat) PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest) AfterEach(org.junit.jupiter.api.AfterEach) FieldType(org.springframework.data.elasticsearch.annotations.FieldType) GetTemplateRequest(org.springframework.data.elasticsearch.core.index.GetTemplateRequest) LocalDate(java.time.LocalDate) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Id(org.springframework.data.annotation.Id) Set(java.util.Set) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) StepVerifier(reactor.test.StepVerifier) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

AliasActions (org.springframework.data.elasticsearch.core.index.AliasActions)9 AliasAction (org.springframework.data.elasticsearch.core.index.AliasAction)8 Test (org.junit.jupiter.api.Test)7 AliasActionParameters (org.springframework.data.elasticsearch.core.index.AliasActionParameters)5 PutTemplateRequest (org.springframework.data.elasticsearch.core.index.PutTemplateRequest)5 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)5 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)4 Settings (org.springframework.data.elasticsearch.core.index.Settings)4 LocalDate (java.time.LocalDate)3 Map (java.util.Map)3 UUID (java.util.UUID)3 Assertions (org.assertj.core.api.Assertions)3 JSONException (org.json.JSONException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 JSONAssert (org.skyscreamer.jsonassert.JSONAssert)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Configuration (org.springframework.context.annotation.Configuration)3 Import (org.springframework.context.annotation.Import)3 Id (org.springframework.data.annotation.Id)3 Document (org.springframework.data.elasticsearch.annotations.Document)3