Search in sources :

Example 1 with OpenIndexResponse

use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.

the class OpenCloseIndexIT method testOpenOneMissingIndexIgnoreMissing.

public void testOpenOneMissingIndexIgnoreMissing() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1", "test2").setIndicesOptions(IndicesOptions.lenientExpandOpen()).execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) Client(org.opensearch.client.Client)

Example 2 with OpenIndexResponse

use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.

the class OpenCloseIndexIT method testCloseOpenWildcard.

public void testCloseOpenWildcard() {
    Client client = client();
    createIndex("test1", "test2", "a");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    AcknowledgedResponse closeIndexResponse = client.admin().indices().prepareClose("test*").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    assertIndexIsOpened("a");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test*").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2", "a");
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) Client(org.opensearch.client.Client)

Example 3 with OpenIndexResponse

use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.

the class OpenCloseIndexIT method testCloseOpenAliasMultipleIndices.

public void testCloseOpenAliasMultipleIndices() {
    Client client = client();
    createIndex("test1", "test2");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    AcknowledgedResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
    assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
    AcknowledgedResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
    assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));
    AcknowledgedResponse closeIndexResponse = client.admin().indices().prepareClose("test-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertThat(openIndexResponse.isShardsAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2");
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) Client(org.opensearch.client.Client)

Example 4 with OpenIndexResponse

use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.

the class IndicesClientIT method testOpenExistingIndex.

public void testOpenExistingIndex() throws IOException {
    String index = "index";
    createIndex(index, Settings.EMPTY);
    closeIndex(index);
    ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
    assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
    assertThat(exception.getMessage().contains(index), equalTo(true));
    OpenIndexRequest openIndexRequest = new OpenIndexRequest(index);
    OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync);
    assertTrue(openIndexResponse.isAcknowledged());
    Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
    assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
}
Also used : CloseIndexResponse(org.opensearch.client.indices.CloseIndexResponse) SimulateIndexTemplateResponse(org.opensearch.client.indices.SimulateIndexTemplateResponse) RolloverResponse(org.opensearch.client.indices.rollover.RolloverResponse) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) GetMappingsResponse(org.opensearch.client.indices.GetMappingsResponse) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) GetIndexResponse(org.opensearch.client.indices.GetIndexResponse) DataStreamsStatsResponse(org.opensearch.client.indices.DataStreamsStatsResponse) GetDataStreamResponse(org.opensearch.client.indices.GetDataStreamResponse) ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) GetIndexTemplatesResponse(org.opensearch.client.indices.GetIndexTemplatesResponse) GetFieldMappingsResponse(org.opensearch.client.indices.GetFieldMappingsResponse) AnalyzeResponse(org.opensearch.client.indices.AnalyzeResponse) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) GetComposableIndexTemplatesResponse(org.opensearch.client.indices.GetComposableIndexTemplatesResponse) ClearIndicesCacheResponse(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) 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) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with OpenIndexResponse

use of org.opensearch.action.admin.indices.open.OpenIndexResponse in project OpenSearch by opensearch-project.

the class IndicesClientIT method testOpenNonExistentIndex.

public void testOpenNonExistentIndex() throws IOException {
    String nonExistentIndex = "non_existent_index";
    assertFalse(indexExists(nonExistentIndex));
    OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex);
    OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
    assertEquals(RestStatus.NOT_FOUND, exception.status());
    OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
    lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
    OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync);
    assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true));
    OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
    strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen());
    OpenSearchException strictException = expectThrows(OpenSearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
    assertEquals(RestStatus.NOT_FOUND, strictException.status());
}
Also used : OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) OpenSearchException(org.opensearch.OpenSearchException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

OpenIndexResponse (org.opensearch.action.admin.indices.open.OpenIndexResponse)14 Client (org.opensearch.client.Client)10 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)9 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)9 Matchers.containsString (org.hamcrest.Matchers.containsString)3 OpenIndexRequest (org.opensearch.action.admin.indices.open.OpenIndexRequest)2 OpenSearchException (org.opensearch.OpenSearchException)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)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 ClearIndicesCacheResponse (org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse)1 DeleteIndexRequest (org.opensearch.action.admin.indices.delete.DeleteIndexRequest)1 FlushRequest (org.opensearch.action.admin.indices.flush.FlushRequest)1 FlushResponse (org.opensearch.action.admin.indices.flush.FlushResponse)1 ForceMergeRequest (org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest)1 ForceMergeResponse (org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse)1 RefreshRequest (org.opensearch.action.admin.indices.refresh.RefreshRequest)1 RefreshResponse (org.opensearch.action.admin.indices.refresh.RefreshResponse)1 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)1