Search in sources :

Example 1 with TemplateData

use of org.springframework.data.elasticsearch.core.index.TemplateData in project spring-data-elasticsearch by spring-projects.

the class ReactiveIndexTemplate method getTemplate.

@Override
public Mono<TemplateData> getTemplate(GetTemplateRequest getTemplateRequest) {
    Assert.notNull(getTemplateRequest, "getTemplateRequest must not be null");
    GetIndexTemplatesRequest getIndexTemplatesRequest = requestFactory.getIndexTemplatesRequest(getTemplateRequest);
    return Mono.from(operations.executeWithIndicesClient(client -> client.getTemplate(getIndexTemplatesRequest))).flatMap(response -> {
        if (response != null) {
            TemplateData templateData = ResponseConverter.getTemplateData(response, getTemplateRequest.getTemplateName());
            if (templateData != null) {
                return Mono.just(templateData);
            }
        }
        return Mono.empty();
    });
}
Also used : TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) GetIndexTemplatesRequest(org.elasticsearch.client.indices.GetIndexTemplatesRequest)

Example 2 with TemplateData

use of org.springframework.data.elasticsearch.core.index.TemplateData in project spring-data-elasticsearch by spring-projects.

the class ReactiveIndexOperationsTest method shouldGetTemplate.

// DATAES-612
@Test
void shouldGetTemplate() throws JSONException {
    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();
    GetTemplateRequest getTemplateRequest = new GetTemplateRequest(putTemplateRequest.getName());
    TemplateData templateData = indexOps.getTemplate(getTemplateRequest).block();
    assertThat(templateData).isNotNull();
    assertThat(templateData.getIndexPatterns()).containsExactlyInAnyOrder(putTemplateRequest.getIndexPatterns());
    assertEquals(settings.toJson(), templateData.getSettings().toJson(), false);
    assertEquals(mapping.toJson(), templateData.getMapping().toJson(), false);
    Map<String, AliasData> aliases = templateData.getAliases();
    assertThat(aliases).hasSize(2);
    AliasData alias1 = aliases.get("alias1");
    assertThat(alias1.getAlias()).isEqualTo("alias1");
    AliasData alias2 = aliases.get("alias2");
    assertThat(alias2.getAlias()).isEqualTo("alias2");
    assertThat(templateData.getOrder()).isEqualTo(putTemplateRequest.getOrder());
    assertThat(templateData.getVersion()).isEqualTo(putTemplateRequest.getVersion());
}
Also used : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) GetTemplateRequest(org.springframework.data.elasticsearch.core.index.GetTemplateRequest) Settings(org.springframework.data.elasticsearch.core.index.Settings) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Aggregations

TemplateData (org.springframework.data.elasticsearch.core.index.TemplateData)2 GetIndexTemplatesRequest (org.elasticsearch.client.indices.GetIndexTemplatesRequest)1 Test (org.junit.jupiter.api.Test)1 AliasAction (org.springframework.data.elasticsearch.core.index.AliasAction)1 AliasActions (org.springframework.data.elasticsearch.core.index.AliasActions)1 AliasData (org.springframework.data.elasticsearch.core.index.AliasData)1 GetTemplateRequest (org.springframework.data.elasticsearch.core.index.GetTemplateRequest)1 PutTemplateRequest (org.springframework.data.elasticsearch.core.index.PutTemplateRequest)1 Settings (org.springframework.data.elasticsearch.core.index.Settings)1 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)1