use of org.opensearch.client.indices.DeleteComposableIndexTemplateRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method deleteIndexTemplate.
static Request deleteIndexTemplate(DeleteComposableIndexTemplateRequest deleteIndexTemplateRequest) {
String name = deleteIndexTemplateRequest.getName();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template").addPathPart(name).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withMasterTimeout(deleteIndexTemplateRequest.masterNodeTimeout());
request.addParameters(params.asMap());
return request;
}
use of org.opensearch.client.indices.DeleteComposableIndexTemplateRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testIndexTemplates.
public void testIndexTemplates() throws Exception {
String templateName = "my-template";
Settings settings = Settings.builder().put("index.number_of_shards", 1).build();
CompressedXContent mappings = new CompressedXContent("{\"properties\":{\"host_name\":{\"type\":\"keyword\"}}}");
AliasMetadata alias = AliasMetadata.builder("alias").writeIndex(true).build();
Template template = new Template(settings, mappings, Collections.singletonMap("alias", alias));
List<String> pattern = Collections.singletonList("pattern");
ComposableIndexTemplate indexTemplate = new ComposableIndexTemplate(pattern, template, Collections.emptyList(), 1L, 1L, new HashMap<>(), null);
PutComposableIndexTemplateRequest putComposableIndexTemplateRequest = new PutComposableIndexTemplateRequest().name(templateName).create(true).indexTemplate(indexTemplate);
AcknowledgedResponse response = execute(putComposableIndexTemplateRequest, highLevelClient().indices()::putIndexTemplate, highLevelClient().indices()::putIndexTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true));
ComposableIndexTemplateExistRequest composableIndexTemplateExistRequest = new ComposableIndexTemplateExistRequest(templateName);
boolean exist = execute(composableIndexTemplateExistRequest, highLevelClient().indices()::existsIndexTemplate, highLevelClient().indices()::existsIndexTemplateAsync);
assertTrue(exist);
GetComposableIndexTemplateRequest getComposableIndexTemplateRequest = new GetComposableIndexTemplateRequest(templateName);
GetComposableIndexTemplatesResponse getResponse = execute(getComposableIndexTemplateRequest, highLevelClient().indices()::getIndexTemplate, highLevelClient().indices()::getIndexTemplateAsync);
assertThat(getResponse.getIndexTemplates().size(), equalTo(1));
assertThat(getResponse.getIndexTemplates().containsKey(templateName), equalTo(true));
assertThat(getResponse.getIndexTemplates().get(templateName), equalTo(indexTemplate));
DeleteComposableIndexTemplateRequest deleteComposableIndexTemplateRequest = new DeleteComposableIndexTemplateRequest(templateName);
response = execute(deleteComposableIndexTemplateRequest, highLevelClient().indices()::deleteIndexTemplate, highLevelClient().indices()::deleteIndexTemplateAsync);
assertThat(response.isAcknowledged(), equalTo(true));
OpenSearchStatusException statusException = expectThrows(OpenSearchStatusException.class, () -> execute(getComposableIndexTemplateRequest, highLevelClient().indices()::getIndexTemplate, highLevelClient().indices()::getIndexTemplateAsync));
assertThat(statusException.status(), equalTo(RestStatus.NOT_FOUND));
exist = execute(composableIndexTemplateExistRequest, highLevelClient().indices()::existsIndexTemplate, highLevelClient().indices()::existsIndexTemplateAsync);
assertFalse(exist);
}
use of org.opensearch.client.indices.DeleteComposableIndexTemplateRequest in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testDeleteIndexTemplateV2.
public void testDeleteIndexTemplateV2() throws Exception {
RestHighLevelClient client = highLevelClient();
{
PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template");
ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("pattern-1", "log-*"), null, null, null, null, null);
// <2>
request.indexTemplate(composableIndexTemplate);
assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
// tag::delete-index-template-v2-request
// <1>
DeleteComposableIndexTemplateRequest deleteRequest = new DeleteComposableIndexTemplateRequest("my-template");
// end::delete-index-template-v2-request
// tag::delete-index-template-v2-request-masterTimeout
// <1>
deleteRequest.setMasterTimeout(TimeValue.timeValueMinutes(1));
// end::delete-index-template-v2-request-masterTimeout
// tag::delete-index-template-v2-execute
AcknowledgedResponse deleteTemplateAcknowledge = client.indices().deleteIndexTemplate(deleteRequest, RequestOptions.DEFAULT);
// end::delete-index-template-v2-execute
// tag::delete-index-template-v2-response
// <1>
boolean acknowledged = deleteTemplateAcknowledge.isAcknowledged();
// end::delete-index-template-v2-response
assertThat(acknowledged, equalTo(true));
{
PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template");
ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("pattern-1", "log-*"), null, null, null, null, null);
// <2>
request.indexTemplate(composableIndexTemplate);
assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
// tag::delete-index-template-v2-execute-listener
ActionListener<AcknowledgedResponse> listener = new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse response) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::delete-index-template-v2-execute-listener
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::delete-index-template-v2-execute-async
// <1>
client.indices().deleteIndexTemplateAsync(deleteRequest, RequestOptions.DEFAULT, listener);
// end::delete-index-template-v2-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Aggregations