Search in sources :

Example 1 with ComposableIndexTemplateExistRequest

use of org.opensearch.client.indices.ComposableIndexTemplateExistRequest in project OpenSearch by opensearch-project.

the class IndicesRequestConverters method templatesExist.

static Request templatesExist(ComposableIndexTemplateExistRequest indexTemplatesExistRequest) {
    final String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template").addPathPart(indexTemplatesExistRequest.name()).build();
    final Request request = new Request(HttpHead.METHOD_NAME, endpoint);
    final RequestConverters.Params params = new RequestConverters.Params();
    params.withLocal(indexTemplatesExistRequest.isLocal());
    params.withMasterTimeout(indexTemplatesExistRequest.getMasterNodeTimeout());
    request.addParameters(params.asMap());
    return request;
}
Also used : UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest)

Example 2 with ComposableIndexTemplateExistRequest

use of org.opensearch.client.indices.ComposableIndexTemplateExistRequest 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);
}
Also used : ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Template(org.opensearch.cluster.metadata.Template) CompressedXContent(org.opensearch.common.compress.CompressedXContent) GetComposableIndexTemplatesResponse(org.opensearch.client.indices.GetComposableIndexTemplatesResponse) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) OpenSearchStatusException(org.opensearch.OpenSearchStatusException)

Aggregations

ComposableIndexTemplateExistRequest (org.opensearch.client.indices.ComposableIndexTemplateExistRequest)2 DeleteComposableIndexTemplateRequest (org.opensearch.client.indices.DeleteComposableIndexTemplateRequest)2 GetComposableIndexTemplateRequest (org.opensearch.client.indices.GetComposableIndexTemplateRequest)2 PutComposableIndexTemplateRequest (org.opensearch.client.indices.PutComposableIndexTemplateRequest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 OpenSearchStatusException (org.opensearch.OpenSearchStatusException)1 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)1 GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)1 ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)1 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)1 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)1 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)1 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)1 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)1 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)1 UpdateSettingsRequest (org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest)1 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)1 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)1