Search in sources :

Example 71 with ClusterHealthResponse

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

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));
    assertIndexIsOpened("test1");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client)

Example 72 with ClusterHealthResponse

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

the class OpenCloseIndexIT method testOpenOneMissingIndex.

public void testOpenOneMissingIndex() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    Exception e = expectThrows(IndexNotFoundException.class, () -> client.admin().indices().prepareOpen("test1", "test2").execute().actionGet());
    assertThat(e.getMessage(), is("no such index"));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Client(org.elasticsearch.client.Client) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Example 73 with ClusterHealthResponse

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

the class OpenCloseIndexIT method testCloseOpenAllWildcard.

public void testCloseOpenAllWildcard() {
    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("*").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2", "test3");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("*").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)

Example 74 with ClusterHealthResponse

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

the class SearchWhileRelocatingIT method testSearchAndRelocateConcurrently.

private void testSearchAndRelocateConcurrently(final int numberOfReplicas) throws Exception {
    final int numShards = between(1, 20);
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", numShards).put("index.number_of_replicas", numberOfReplicas)).addMapping("type", "loc", "type=geo_point", "test", "type=text").execute().actionGet();
    ensureGreen();
    List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
    final int numDocs = between(10, 20);
    for (int i = 0; i < numDocs; i++) {
        indexBuilders.add(client().prepareIndex("test", "type", Integer.toString(i)).setSource(jsonBuilder().startObject().field("test", "value").startObject("loc").field("lat", 11).field("lon", 21).endObject().endObject()));
    }
    indexRandom(true, indexBuilders.toArray(new IndexRequestBuilder[indexBuilders.size()]));
    assertHitCount(client().prepareSearch().get(), (numDocs));
    final int numIters = scaledRandomIntBetween(5, 20);
    for (int i = 0; i < numIters; i++) {
        final AtomicBoolean stop = new AtomicBoolean(false);
        final List<String> nonCriticalExceptions = new CopyOnWriteArrayList<>();
        Thread[] threads = new Thread[scaledRandomIntBetween(1, 3)];
        for (int j = 0; j < threads.length; j++) {
            threads[j] = new Thread() {

                @Override
                public void run() {
                    try {
                        while (!stop.get()) {
                            SearchResponse sr = client().prepareSearch().setSize(numDocs).get();
                            if (sr.getHits().getTotalHits() != numDocs) {
                                // request comes in. It's a small window but a known limitation.
                                if (sr.getTotalShards() != sr.getSuccessfulShards() && sr.getFailedShards() == 0) {
                                    nonCriticalExceptions.add("Count is " + sr.getHits().getTotalHits() + " but " + numDocs + " was expected. " + formatShardStatus(sr));
                                } else {
                                    assertHitCount(sr, numDocs);
                                }
                            }
                            final SearchHits sh = sr.getHits();
                            assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits(), equalTo((long) (sh.getHits().length)));
                        // this is the more critical but that we hit the actual hit array has a different size than the
                        // actual number of hits.
                        }
                    } catch (SearchPhaseExecutionException ex) {
                        // with replicas this should not happen
                        if (numberOfReplicas == 1 || !ex.getMessage().contains("all shards failed")) {
                            throw ex;
                        }
                    }
                }
            };
        }
        for (int j = 0; j < threads.length; j++) {
            threads[j].start();
        }
        allowNodes("test", between(1, 3));
        client().admin().cluster().prepareReroute().get();
        stop.set(true);
        for (int j = 0; j < threads.length; j++) {
            threads[j].join();
        }
        // this might time out on some machines if they are really busy and you hit lots of throttling
        ClusterHealthResponse resp = client().admin().cluster().prepareHealth().setWaitForYellowStatus().setWaitForNoRelocatingShards(true).setWaitForEvents(Priority.LANGUID).setTimeout("5m").get();
        assertNoTimeout(resp);
        // if we hit only non-critical exceptions we make sure that the post search works
        if (!nonCriticalExceptions.isEmpty()) {
            logger.info("non-critical exceptions: {}", nonCriticalExceptions);
            for (int j = 0; j < 10; j++) {
                assertHitCount(client().prepareSearch().get(), numDocs);
            }
        }
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SearchHits(org.elasticsearch.search.SearchHits) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 75 with ClusterHealthResponse

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

the class TransportSearchFailuresIT method testFailedSearchWithWrongQuery.

public void testFailedSearchWithWrongQuery() throws Exception {
    logger.info("Start Testing failed search with wrong query");
    assertAcked(prepareCreate("test", 1).addMapping("type", "foo", "type=geo_point"));
    NumShards test = getNumShards("test");
    for (int i = 0; i < 100; i++) {
        index(client(), Integer.toString(i), "test", i);
    }
    RefreshResponse refreshResponse = client().admin().indices().refresh(refreshRequest("test")).actionGet();
    assertThat(refreshResponse.getTotalShards(), equalTo(test.totalNumShards));
    assertThat(refreshResponse.getSuccessfulShards(), equalTo(test.numPrimaries));
    assertThat(refreshResponse.getFailedShards(), equalTo(0));
    for (int i = 0; i < 5; i++) {
        try {
            SearchResponse searchResponse = client().search(searchRequest("test").source(new SearchSourceBuilder().query(new MatchQueryBuilder("foo", "biz")))).actionGet();
            assertThat(searchResponse.getTotalShards(), equalTo(test.numPrimaries));
            assertThat(searchResponse.getSuccessfulShards(), equalTo(0));
            assertThat(searchResponse.getFailedShards(), equalTo(test.numPrimaries));
            fail("search should fail");
        } catch (ElasticsearchException e) {
            assertThat(e.unwrapCause(), instanceOf(SearchPhaseExecutionException.class));
        // all is well
        }
    }
    allowNodes("test", 2);
    assertThat(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes(">=2").execute().actionGet().isTimedOut(), equalTo(false));
    logger.info("Running Cluster Health");
    ClusterHealthResponse clusterHealth = client().admin().cluster().health(clusterHealthRequest("test").waitForYellowStatus().waitForNoRelocatingShards(true).waitForActiveShards(test.totalNumShards)).actionGet();
    logger.info("Done Cluster Health, status {}", clusterHealth.getStatus());
    assertThat(clusterHealth.isTimedOut(), equalTo(false));
    assertThat(clusterHealth.getStatus(), anyOf(equalTo(ClusterHealthStatus.YELLOW), equalTo(ClusterHealthStatus.GREEN)));
    assertThat(clusterHealth.getActiveShards(), equalTo(test.totalNumShards));
    refreshResponse = client().admin().indices().refresh(refreshRequest("test")).actionGet();
    assertThat(refreshResponse.getTotalShards(), equalTo(test.totalNumShards));
    assertThat(refreshResponse.getSuccessfulShards(), equalTo(test.totalNumShards));
    assertThat(refreshResponse.getFailedShards(), equalTo(0));
    for (int i = 0; i < 5; i++) {
        try {
            SearchResponse searchResponse = client().search(searchRequest("test").source(new SearchSourceBuilder().query(new MatchQueryBuilder("foo", "biz")))).actionGet();
            assertThat(searchResponse.getTotalShards(), equalTo(test.numPrimaries));
            assertThat(searchResponse.getSuccessfulShards(), equalTo(0));
            assertThat(searchResponse.getFailedShards(), equalTo(test.numPrimaries));
            fail("search should fail");
        } catch (ElasticsearchException e) {
            assertThat(e.unwrapCause(), instanceOf(SearchPhaseExecutionException.class));
        // all is well
        }
    }
    logger.info("Done Testing failed search");
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchResponse(org.elasticsearch.action.search.SearchResponse) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

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