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