Search in sources :

Example 66 with ClusterHealthResponse

use of org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.

the class SimpleGetMappingsIT method testSimpleGetMappings.

public void testSimpleGetMappings() throws Exception {
    client().admin().indices().prepareCreate("indexa").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
    client().admin().indices().prepareCreate("indexb").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
    ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
    assertThat(clusterHealth.isTimedOut(), equalTo(false));
    // Get all mappings
    GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
    assertThat(response.mappings().size(), equalTo(2));
    assertThat(response.mappings().get("indexa").size(), equalTo(4));
    assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
    assertThat(response.mappings().get("indexb").size(), equalTo(4));
    assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
    assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
    // Get all mappings, via wildcard support
    response = client().admin().indices().prepareGetMappings("*").setTypes("*").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(2));
    assertThat(response.mappings().get("indexa").size(), equalTo(4));
    assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
    assertThat(response.mappings().get("indexb").size(), equalTo(4));
    assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
    assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
    // Get all typeA mappings in all indices
    response = client().admin().indices().prepareGetMappings("*").setTypes("typeA").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(2));
    assertThat(response.mappings().get("indexa").size(), equalTo(1));
    assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexb").size(), equalTo(1));
    assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
    // Get all mappings in indexa
    response = client().admin().indices().prepareGetMappings("indexa").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(1));
    assertThat(response.mappings().get("indexa").size(), equalTo(4));
    assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
    assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
    // Get all mappings beginning with A* in indexa
    response = client().admin().indices().prepareGetMappings("indexa").setTypes("A*").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(1));
    assertThat(response.mappings().get("indexa").size(), equalTo(1));
    assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
    // Get all mappings beginning with B* in all indices
    response = client().admin().indices().prepareGetMappings().setTypes("B*").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(2));
    assertThat(response.mappings().get("indexa").size(), equalTo(1));
    assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
    assertThat(response.mappings().get("indexb").size(), equalTo(1));
    assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
    // Get all mappings beginning with B* and A* in all indices
    response = client().admin().indices().prepareGetMappings().setTypes("B*", "A*").execute().actionGet();
    assertThat(response.mappings().size(), equalTo(2));
    assertThat(response.mappings().get("indexa").size(), equalTo(2));
    assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
    assertThat(response.mappings().get("indexb").size(), equalTo(2));
    assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
    assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 67 with ClusterHealthResponse

use of org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testCloseOpenMultipleIndices.

public void testCloseOpenMultipleIndices() {
    Client client = client();
    createIndex("test1", "test2", "test3");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    CloseIndexResponse closeIndexResponse1 = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse1.isAcknowledged(), equalTo(true));
    CloseIndexResponse closeIndexResponse2 = client.admin().indices().prepareClose("test2").execute().actionGet();
    assertThat(closeIndexResponse2.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    assertIndexIsOpened("test3");
    OpenIndexResponse openIndexResponse1 = client.admin().indices().prepareOpen("test1").execute().actionGet();
    assertThat(openIndexResponse1.isAcknowledged(), equalTo(true));
    OpenIndexResponse openIndexResponse2 = client.admin().indices().prepareOpen("test2").execute().actionGet();
    assertThat(openIndexResponse2.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2", "test3");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client)

Example 68 with ClusterHealthResponse

use of org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.

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));
    IndicesAliasesResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
    assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
    IndicesAliasesResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
    assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));
    CloseIndexResponse 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));
    assertIndexIsOpened("test1", "test2");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)

Example 69 with ClusterHealthResponse

use of org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testSimpleCloseOpenAlias.

public void testSimpleCloseOpenAlias() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    IndicesAliasesResponse aliasesResponse = client.admin().indices().prepareAliases().addAlias("test1", "test1-alias").execute().actionGet();
    assertThat(aliasesResponse.isAcknowledged(), equalTo(true));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)

Example 70 with ClusterHealthResponse

use of org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testCloseOpenAll.

public void testCloseOpenAll() {
    Client client = client();
    createIndex("test1", "test2", "test3");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("_all").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2", "test3");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("_all").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2", "test3");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client)

Aggregations

ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)93 Settings (org.elasticsearch.common.settings.Settings)25 Client (org.elasticsearch.client.Client)22 ClusterState (org.elasticsearch.cluster.ClusterState)16 IOException (java.io.IOException)11 SearchResponse (org.elasticsearch.action.search.SearchResponse)10 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)10 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)9 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)9 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)8 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)7 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)7 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)7 Index (org.elasticsearch.index.Index)7 ArrayList (java.util.ArrayList)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Path (java.nio.file.Path)5 ExecutionException (java.util.concurrent.ExecutionException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)4