Search in sources :

Example 11 with RefreshResponse

use of org.elasticsearch.action.admin.indices.refresh.RefreshResponse in project elasticsearch by elastic.

the class SearchWithRandomExceptionsIT method testRandomExceptions.

public void testRandomExceptions() throws IOException, InterruptedException, ExecutionException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "keyword").endObject().endObject().endObject().endObject().string();
    final double lowLevelRate;
    final double topLevelRate;
    if (frequently()) {
        if (randomBoolean()) {
            if (randomBoolean()) {
                lowLevelRate = 1.0 / between(2, 10);
                topLevelRate = 0.0d;
            } else {
                topLevelRate = 1.0 / between(2, 10);
                lowLevelRate = 0.0d;
            }
        } else {
            lowLevelRate = 1.0 / between(2, 10);
            topLevelRate = 1.0 / between(2, 10);
        }
    } else {
        // rarely no exception
        topLevelRate = 0d;
        lowLevelRate = 0d;
    }
    Builder settings = Settings.builder().put(indexSettings()).put(EXCEPTION_TOP_LEVEL_RATIO_KEY, topLevelRate).put(EXCEPTION_LOW_LEVEL_RATIO_KEY, lowLevelRate).put(MockEngineSupport.WRAP_READER_RATIO.getKey(), 1.0d);
    logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap());
    assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", mapping, XContentType.JSON));
    ensureSearchable();
    final int numDocs = between(10, 100);
    int numCreated = 0;
    boolean[] added = new boolean[numDocs];
    for (int i = 0; i < numDocs; i++) {
        try {
            IndexResponse indexResponse = client().prepareIndex("test", "type", "" + i).setTimeout(TimeValue.timeValueSeconds(1)).setSource("test", English.intToEnglish(i)).get();
            if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
                numCreated++;
                added[i] = true;
            }
        } catch (ElasticsearchException ex) {
        }
    }
    logger.info("Start Refresh");
    // don't assert on failures here
    RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().get();
    final boolean refreshFailed = refreshResponse.getShardFailures().length != 0 || refreshResponse.getFailedShards() != 0;
    logger.info("Refresh failed [{}] numShardsFailed: [{}], shardFailuresLength: [{}], successfulShards: [{}], totalShards: [{}] ", refreshFailed, refreshResponse.getFailedShards(), refreshResponse.getShardFailures().length, refreshResponse.getSuccessfulShards(), refreshResponse.getTotalShards());
    NumShards test = getNumShards("test");
    final int numSearches = scaledRandomIntBetween(100, 200);
    // we don't check anything here really just making sure we don't leave any open files or a broken index behind.
    for (int i = 0; i < numSearches; i++) {
        try {
            int docToQuery = between(0, numDocs - 1);
            int expectedResults = added[docToQuery] ? 1 : 0;
            logger.info("Searching for [test:{}]", English.intToEnglish(docToQuery));
            SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.matchQuery("test", English.intToEnglish(docToQuery))).setSize(expectedResults).get();
            logger.info("Successful shards: [{}]  numShards: [{}]", searchResponse.getSuccessfulShards(), test.numPrimaries);
            if (searchResponse.getSuccessfulShards() == test.numPrimaries && !refreshFailed) {
                assertResultsAndLogOnFailure(expectedResults, searchResponse);
            }
            // check match all
            searchResponse = client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).setSize(numCreated).addSort("_id", SortOrder.ASC).get();
            logger.info("Match all Successful shards: [{}]  numShards: [{}]", searchResponse.getSuccessfulShards(), test.numPrimaries);
            if (searchResponse.getSuccessfulShards() == test.numPrimaries && !refreshFailed) {
                assertResultsAndLogOnFailure(numCreated, searchResponse);
            }
        } catch (SearchPhaseExecutionException ex) {
            logger.info("expected SearchPhaseException: [{}]", ex.getMessage());
        }
    }
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) Builder(org.elasticsearch.common.settings.Settings.Builder) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 12 with RefreshResponse

use of org.elasticsearch.action.admin.indices.refresh.RefreshResponse 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)

Example 13 with RefreshResponse

use of org.elasticsearch.action.admin.indices.refresh.RefreshResponse in project elasticsearch by elastic.

the class ESIntegTestCase method refresh.

/**
     * Waits for relocations and refreshes all indices in the cluster.
     *
     * @see #waitForRelocation()
     */
protected final RefreshResponse refresh(String... indices) {
    waitForRelocation();
    // TODO RANDOMIZE with flush?
    RefreshResponse actionGet = client().admin().indices().prepareRefresh(indices).execute().actionGet();
    assertNoFailures(actionGet);
    return actionGet;
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse)

Example 14 with RefreshResponse

use of org.elasticsearch.action.admin.indices.refresh.RefreshResponse in project molgenis by molgenis.

the class ClientFacade method refreshIndexes.

private void refreshIndexes(List<Index> indexes) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Refreshing index(es) '{}' ...", toString(indexes));
    }
    String[] indexNames = toIndexNames(indexes);
    RefreshRequestBuilder refreshRequest = client.admin().indices().prepareRefresh(indexNames);
    RefreshResponse refreshResponse;
    try {
        refreshResponse = refreshRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.debug("", e);
        throw new UnknownIndexException(toIndexNames(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error refreshing index(es) '%s'.", toString(indexes)));
    }
    if (refreshResponse.getFailedShards() > 0) {
        LOG.error(stream(refreshResponse.getShardFailures()).map(ShardOperationFailedException::toString).collect(joining("\n")));
        throw new IndexException(format("Error refreshing index(es) '%s'.", toString(indexes)));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Refreshed index(es) '{}'", toString(indexes));
    }
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) RefreshRequestBuilder(org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder)

Example 15 with RefreshResponse

use of org.elasticsearch.action.admin.indices.refresh.RefreshResponse in project crate by crate.

the class ESIntegTestCase method refresh.

/**
 * Waits for relocations and refreshes all indices in the cluster.
 *
 * @see #waitForRelocation()
 */
protected final RefreshResponse refresh(String... indices) {
    waitForRelocation();
    // TODO RANDOMIZE with flush?
    RefreshResponse actionGet = client().admin().indices().prepareRefresh(indices).execute().actionGet();
    assertNoFailures(actionGet);
    return actionGet;
}
Also used : RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse)

Aggregations

RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)15 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 GetResponse (org.elasticsearch.action.get.GetResponse)3 IndexResponse (org.elasticsearch.action.index.IndexResponse)3 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)3 Settings (org.elasticsearch.common.settings.Settings)3 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)2 FlushResponse (org.elasticsearch.action.admin.indices.flush.FlushResponse)2 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)1 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)1 ClearIndicesCacheResponse (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)1 RefreshRequestBuilder (org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder)1