Search in sources :

Example 1 with CloseIndexRequest

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

the class IndicesClientIT method testCloseNonExistentIndex.

public void testCloseNonExistentIndex() throws IOException {
    String nonExistentIndex = "non_existent_index";
    assertFalse(indexExists(nonExistentIndex));
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex);
    OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
    assertEquals(RestStatus.NOT_FOUND, exception.status());
}
Also used : CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) OpenSearchException(org.opensearch.OpenSearchException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with CloseIndexRequest

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

the class IndicesRequestConverters method closeIndex.

static Request closeIndex(CloseIndexRequest closeIndexRequest) {
    String endpoint = RequestConverters.endpoint(closeIndexRequest.indices(), "_close");
    Request request = new Request(HttpPost.METHOD_NAME, endpoint);
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withTimeout(closeIndexRequest.timeout());
    parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout());
    parameters.withIndicesOptions(closeIndexRequest.indicesOptions());
    request.addParameters(parameters.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 3 with CloseIndexRequest

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

the class IndicesClientIT method testCloseEmptyOrNullIndex.

public void testCloseEmptyOrNullIndex() {
    String[] indices = randomBoolean() ? Strings.EMPTY_ARRAY : null;
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
    org.opensearch.client.ValidationException exception = expectThrows(org.opensearch.client.ValidationException.class, () -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
    assertThat(exception.validationErrors().get(0), equalTo("index is missing"));
}
Also used : CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with CloseIndexRequest

use of org.opensearch.client.indices.CloseIndexRequest 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)

Example 5 with CloseIndexRequest

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

the class IndicesRequestConvertersTests method testCloseIndex.

public void testCloseIndex() {
    String[] indices = RequestConvertersTests.randomIndicesNames(1, 5);
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices);
    Map<String, String> expectedParams = new HashMap<>();
    RequestConvertersTests.setRandomTimeout(timeout -> closeIndexRequest.setTimeout(TimeValue.parseTimeValue(timeout, "test")), AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    RequestConvertersTests.setRandomMasterTimeout(closeIndexRequest, expectedParams);
    RequestConvertersTests.setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions, expectedParams);
    Request request = IndicesRequestConverters.closeIndex(closeIndexRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close");
    Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    Assert.assertThat(expectedParams, equalTo(request.getParameters()));
    Assert.assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
    Assert.assertThat(request.getEntity(), nullValue());
}
Also used : CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) HashMap(java.util.HashMap) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) 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) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) ResizeRequest(org.opensearch.client.indices.ResizeRequest) 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) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) StringJoiner(java.util.StringJoiner)

Aggregations

CloseIndexRequest (org.opensearch.client.indices.CloseIndexRequest)5 Matchers.containsString (org.hamcrest.Matchers.containsString)3 IndicesAliasesRequest (org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)3 GetAliasesRequest (org.opensearch.action.admin.indices.alias.get.GetAliasesRequest)3 ClearIndicesCacheRequest (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)3 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)3 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)3 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)3 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)3 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)3 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)3 UpdateSettingsRequest (org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest)3 DeleteIndexTemplateRequest (org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)3 ValidateQueryRequest (org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest)3 AnalyzeRequest (org.opensearch.client.indices.AnalyzeRequest)3 CreateDataStreamRequest (org.opensearch.client.indices.CreateDataStreamRequest)3 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)3 DeleteAliasRequest (org.opensearch.client.indices.DeleteAliasRequest)3 DeleteDataStreamRequest (org.opensearch.client.indices.DeleteDataStreamRequest)3 GetDataStreamRequest (org.opensearch.client.indices.GetDataStreamRequest)3