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;
}
}
}
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;
}
}
}
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"));
}
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"));
}
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);
}
}
}
}
Aggregations