Search in sources :

Example 1 with CloseIndexResponse

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

the class IndicesClientIT method testCloseExistingIndex.

public void testCloseExistingIndex() throws IOException {
    final String[] indices = new String[randomIntBetween(1, 5)];
    for (int i = 0; i < indices.length; i++) {
        String index = "index-" + i;
        createIndex(index, Settings.EMPTY);
        indices[i] = index;
    }
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
    CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync);
    assertTrue(closeIndexResponse.isAcknowledged());
    assertTrue(closeIndexResponse.isShardsAcknowledged());
    assertThat(closeIndexResponse.getIndices(), notNullValue());
    assertThat(closeIndexResponse.getIndices(), hasSize(indices.length));
    closeIndexResponse.getIndices().forEach(indexResult -> {
        assertThat(indexResult.getIndex(), startsWith("index-"));
        assertThat(indexResult.hasFailures(), is(false));
        ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(new Request(HttpGet.METHOD_NAME, indexResult.getIndex() + "/_search")));
        assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
        assertThat(exception.getMessage().contains(indexResult.getIndex()), equalTo(true));
    });
}
Also used : CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) CloseIndexResponse(org.opensearch.client.indices.CloseIndexResponse) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) WriteRequest(org.opensearch.action.support.WriteRequest) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) IndexRequest(org.opensearch.action.index.IndexRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Matchers.containsString (org.hamcrest.Matchers.containsString)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 ResizeRequest (org.opensearch.action.admin.indices.shrink.ResizeRequest)1 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)1 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)1 IndexRequest (org.opensearch.action.index.IndexRequest)1 WriteRequest (org.opensearch.action.support.WriteRequest)1 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)1 CloseIndexRequest (org.opensearch.client.indices.CloseIndexRequest)1 CloseIndexResponse (org.opensearch.client.indices.CloseIndexResponse)1 ComposableIndexTemplateExistRequest (org.opensearch.client.indices.ComposableIndexTemplateExistRequest)1