Search in sources :

Example 1 with SearchPhaseExecutionException

use of org.opensearch.action.search.SearchPhaseExecutionException in project OpenSearch by opensearch-project.

the class PercentilesBucketIT method testBadPercents.

public void testBadPercents() throws Exception {
    double[] badPercents = { -1.0, 110.0 };
    try {
        client().prepareSearch("idx").addAggregation(terms("terms").field("tag").subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).addAggregation(percentilesBucket("percentiles_bucket", "terms>sum").setPercents(badPercents)).get();
        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
Also used : SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 2 with SearchPhaseExecutionException

use of org.opensearch.action.search.SearchPhaseExecutionException in project OpenSearch by opensearch-project.

the class PercentilesBucketIT method testBadPercents_asSubAgg.

public void testBadPercents_asSubAgg() throws Exception {
    double[] badPercents = { -1.0, 110.0 };
    try {
        client().prepareSearch("idx").addAggregation(terms("terms").field("tag").order(BucketOrder.key(true)).subAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).extendedBounds(minRandomValue, maxRandomValue)).subAggregation(percentilesBucket("percentiles_bucket", "histo>_count").setPercents(badPercents))).get();
        fail("Illegal percent's were provided but no exception was thrown.");
    } catch (Exception e) {
        Throwable cause = ExceptionsHelper.unwrapCause(e);
        if (cause == null) {
            throw e;
        } else if (cause instanceof SearchPhaseExecutionException) {
            SearchPhaseExecutionException spee = (SearchPhaseExecutionException) e;
            Throwable rootCause = spee.getRootCause();
            if (!(rootCause instanceof IllegalArgumentException)) {
                throw e;
            }
        } else if (!(cause instanceof IllegalArgumentException)) {
            throw e;
        }
    }
}
Also used : SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 3 with SearchPhaseExecutionException

use of org.opensearch.action.search.SearchPhaseExecutionException in project OpenSearch by opensearch-project.

the class SearchRedStateIndexIT method testDisallowPartialsWithRedState.

public void testDisallowPartialsWithRedState() throws Exception {
    buildRedIndex(cluster().numDataNodes() + 2);
    SearchPhaseExecutionException ex = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setSize(0).setAllowPartialSearchResults(false).get());
    assertThat(ex.getDetailedMessage(), containsString("Search rejected due to missing shard"));
}
Also used : SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 4 with SearchPhaseExecutionException

use of org.opensearch.action.search.SearchPhaseExecutionException in project OpenSearch by opensearch-project.

the class SearchRedStateIndexIT method testClusterDisallowPartialsWithRedState.

public void testClusterDisallowPartialsWithRedState() throws Exception {
    buildRedIndex(cluster().numDataNodes() + 2);
    setClusterDefaultAllowPartialResults(false);
    SearchPhaseExecutionException ex = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setSize(0).get());
    assertThat(ex.getDetailedMessage(), containsString("Search rejected due to missing shard"));
}
Also used : SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 5 with SearchPhaseExecutionException

use of org.opensearch.action.search.SearchPhaseExecutionException in project OpenSearch by opensearch-project.

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").get();
    ensureGreen();
    List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
    final int numDocs = between(10, 20);
    for (int i = 0; i < numDocs; i++) {
        indexBuilders.add(client().prepareIndex("test").setId(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().value != 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().value + " 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().value, 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.opensearch.action.admin.cluster.health.ClusterHealthResponse) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SearchResponse(org.opensearch.action.search.SearchResponse) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SearchHits(org.opensearch.search.SearchHits) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)42 SearchResponse (org.opensearch.action.search.SearchResponse)14 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ShardSearchFailure (org.opensearch.action.search.ShardSearchFailure)8 SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)5 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)5 IOException (java.io.IOException)4 OpenSearchException (org.opensearch.OpenSearchException)4 ArrayList (java.util.ArrayList)3 RefreshResponse (org.opensearch.action.admin.indices.refresh.RefreshResponse)3 ClusterBlockException (org.opensearch.cluster.block.ClusterBlockException)3 ParsingException (org.opensearch.common.ParsingException)3 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)2 IndexResponse (org.opensearch.action.index.IndexResponse)2 MultiSearchResponse (org.opensearch.action.search.MultiSearchResponse)2 Settings (org.opensearch.common.settings.Settings)2 ShardId (org.opensearch.index.shard.ShardId)2 Script (org.opensearch.script.Script)2