Search in sources :

Example 1 with ExistsTemplateRequest

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

the class RestIndexTemplate method getTemplate.

@Override
public TemplateData getTemplate(GetTemplateRequest getTemplateRequest) {
    Assert.notNull(getTemplateRequest, "getTemplateRequest must not be null");
    // getIndexTemplate throws an error on non-existing template names
    if (!existsTemplate(new ExistsTemplateRequest(getTemplateRequest.getTemplateName()))) {
        return null;
    }
    GetIndexTemplatesRequest getIndexTemplatesRequest = requestFactory.getIndexTemplatesRequest(getTemplateRequest);
    GetIndexTemplatesResponse getIndexTemplatesResponse = restTemplate.execute(client -> client.indices().getIndexTemplate(getIndexTemplatesRequest, RequestOptions.DEFAULT));
    return ResponseConverter.getTemplateData(getIndexTemplatesResponse, getTemplateRequest.getTemplateName());
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.client.indices.GetIndexTemplatesResponse) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) GetIndexTemplatesRequest(org.elasticsearch.client.indices.GetIndexTemplatesRequest)

Example 2 with ExistsTemplateRequest

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

the class ReactiveIndexOperationsTest method shouldCheckExists.

// DATAES-612
@Test
void shouldCheckExists() {
    ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
    String templateName = "template" + UUID.randomUUID().toString();
    ExistsTemplateRequest existsTemplateRequest = new ExistsTemplateRequest(templateName);
    boolean exists = indexOps.existsTemplate(existsTemplateRequest).block();
    assertThat(exists).isFalse();
    PutTemplateRequest putTemplateRequest = // 
    PutTemplateRequest.builder(templateName, "log-*").withOrder(// 
    11).withVersion(// 
    42).build();
    boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
    assertThat(acknowledged).isTrue();
    exists = indexOps.existsTemplate(existsTemplateRequest).block();
    assertThat(exists).isTrue();
}
Also used : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 3 with ExistsTemplateRequest

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

the class ReactiveIndexOperationsTest method shouldDeleteTemplate.

// DATAES-612
@Test
void shouldDeleteTemplate() {
    ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
    String templateName = "template" + UUID.randomUUID().toString();
    ExistsTemplateRequest existsTemplateRequest = new ExistsTemplateRequest(templateName);
    PutTemplateRequest putTemplateRequest = // 
    PutTemplateRequest.builder(templateName, "log-*").withOrder(// 
    11).withVersion(// 
    42).build();
    boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
    assertThat(acknowledged).isTrue();
    boolean exists = indexOps.existsTemplate(existsTemplateRequest).block();
    assertThat(exists).isTrue();
    acknowledged = indexOps.deleteTemplate(new DeleteTemplateRequest(templateName)).block();
    assertThat(acknowledged).isTrue();
    exists = indexOps.existsTemplate(existsTemplateRequest).block();
    assertThat(exists).isFalse();
}
Also used : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) DeleteTemplateRequest(org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 4 with ExistsTemplateRequest

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

the class ReactiveIndexTemplate method existsTemplate.

@Override
public Mono<Boolean> existsTemplate(ExistsTemplateRequest existsTemplateRequest) {
    Assert.notNull(existsTemplateRequest, "existsTemplateRequest must not be null");
    IndexTemplatesExistRequest indexTemplatesExistRequest = requestFactory.indexTemplatesExistsRequest(existsTemplateRequest);
    return Mono.from(operations.executeWithIndicesClient(client -> client.existsTemplate(indexTemplatesExistRequest)));
}
Also used : AnnotatedElementUtils(org.springframework.core.annotation.AnnotatedElementUtils) GetMappingsRequest(org.elasticsearch.client.indices.GetMappingsRequest) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Settings(org.springframework.data.elasticsearch.core.index.Settings) PutIndexTemplateRequest(org.elasticsearch.client.indices.PutIndexTemplateRequest) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException) ElasticsearchPersistentEntity(org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity) Mapping(org.springframework.data.elasticsearch.annotations.Mapping) ElasticsearchConverter(org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter) GetAliasesResponse(org.elasticsearch.client.GetAliasesResponse) Map(java.util.Map) Nullable(org.springframework.lang.Nullable) Requests(org.elasticsearch.client.Requests) AliasData(org.springframework.data.elasticsearch.core.index.AliasData) ReactiveMappingBuilder(org.springframework.data.elasticsearch.core.index.ReactiveMappingBuilder) TemplateData(org.springframework.data.elasticsearch.core.index.TemplateData) IndexTemplatesExistRequest(org.elasticsearch.client.indices.IndexTemplatesExistRequest) DeleteTemplateRequest(org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest) ExistsTemplateRequest(org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) GetIndexTemplatesRequest(org.elasticsearch.client.indices.GetIndexTemplatesRequest) Set(java.util.Set) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) Mono(reactor.core.publisher.Mono) PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Flux(reactor.core.publisher.Flux) GetTemplateRequest(org.springframework.data.elasticsearch.core.index.GetTemplateRequest) NoSuchIndexException(org.springframework.data.elasticsearch.NoSuchIndexException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) Document(org.springframework.data.elasticsearch.core.document.Document) StringUtils(org.springframework.util.StringUtils) Assert(org.springframework.util.Assert) IndexTemplatesExistRequest(org.elasticsearch.client.indices.IndexTemplatesExistRequest)

Aggregations

ExistsTemplateRequest (org.springframework.data.elasticsearch.core.index.ExistsTemplateRequest)4 PutTemplateRequest (org.springframework.data.elasticsearch.core.index.PutTemplateRequest)3 GetIndexTemplatesRequest (org.elasticsearch.client.indices.GetIndexTemplatesRequest)2 Test (org.junit.jupiter.api.Test)2 DeleteTemplateRequest (org.springframework.data.elasticsearch.core.index.DeleteTemplateRequest)2 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)2 Map (java.util.Map)1 Set (java.util.Set)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)1 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)1 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)1 GetAliasesResponse (org.elasticsearch.client.GetAliasesResponse)1 Requests (org.elasticsearch.client.Requests)1 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)1 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)1 GetIndexTemplatesResponse (org.elasticsearch.client.indices.GetIndexTemplatesResponse)1