use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.
the class BytesRestResponseTests method testConvert.
public void testConvert() throws IOException {
RestRequest request = new FakeRestRequest();
RestChannel channel = new DetailedExceptionRestChannel(request);
ShardSearchFailure failure = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 1));
ShardSearchFailure failure1 = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 2));
SearchPhaseExecutionException ex = new SearchPhaseExecutionException("search", "all shards failed", new ShardSearchFailure[] { failure, failure1 });
BytesRestResponse response = new BytesRestResponse(channel, new RemoteTransportException("foo", ex));
String text = response.content().utf8ToString();
String expected = "{\"error\":{\"root_cause\":[{\"type\":\"parsing_exception\",\"reason\":\"foobar\",\"line\":1,\"col\":2}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"search\",\"grouped\":true,\"failed_shards\":[{\"shard\":1,\"index\":\"foo\",\"node\":\"node_1\",\"reason\":{\"type\":\"parsing_exception\",\"reason\":\"foobar\",\"line\":1,\"col\":2}}]},\"status\":400}";
assertEquals(expected.trim(), text.trim());
String stackTrace = ExceptionsHelper.stackTrace(ex);
assertTrue(stackTrace.contains("Caused by: ParsingException[foobar]"));
}
use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.
the class SearchSliceIT method testInvalidFields.
public void testInvalidFields() throws Exception {
setupIndex(false);
SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test").setQuery(matchAllQuery()).setScroll(new Scroll(TimeValue.timeValueSeconds(10))).slice(new SliceBuilder("invalid_random_int", 0, 10)).get());
Throwable rootCause = findRootCause(exc);
assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), startsWith("cannot load numeric doc values"));
exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test").setQuery(matchAllQuery()).setScroll(new Scroll(TimeValue.timeValueSeconds(10))).slice(new SliceBuilder("invalid_random_kw", 0, 10)).get());
rootCause = findRootCause(exc);
assertThat(rootCause.getClass(), equalTo(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), startsWith("cannot load numeric doc values"));
}
use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.
the class FieldSortIT method testIgnoreUnmapped.
public void testIgnoreUnmapped() throws Exception {
createIndex("test");
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("id", "1").field("i_value", -1).field("d_value", -1.1).endObject()).execute().actionGet();
logger.info("--> sort with an unmapped field, verify it fails");
try {
SearchResponse result = client().prepareSearch().setQuery(matchAllQuery()).addSort(SortBuilders.fieldSort("kkk")).execute().actionGet();
assertThat("Expected exception but returned with", result, nullValue());
} catch (SearchPhaseExecutionException e) {
//we check that it's a parse failure rather than a different shard failure
for (ShardSearchFailure shardSearchFailure : e.shardFailures()) {
assertThat(shardSearchFailure.toString(), containsString("[No mapping found for [kkk] in order to sort on]"));
}
}
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).addSort(SortBuilders.fieldSort("kkk").unmappedType("keyword")).execute().actionGet();
assertNoFailures(searchResponse);
}
use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.
the class SearchQueryIT method testDateRangeInQueryString.
// Issue #3540
public void testDateRangeInQueryString() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
//as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping("type", "past", "type=date", "future", "type=date"));
String aMonthAgo = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).minusMonths(1));
String aMonthFromNow = ISODateTimeFormat.yearMonthDay().print(new DateTime(DateTimeZone.UTC).plusMonths(1));
client().prepareIndex("test", "type", "1").setSource("past", aMonthAgo, "future", aMonthFromNow).get();
refresh();
SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-2M/d TO now/d]")).get();
assertHitCount(searchResponse, 1L);
searchResponse = client().prepareSearch().setQuery(queryStringQuery("future:[now/d TO now+2M/d]")).get();
assertHitCount(searchResponse, 1L);
SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setQuery(queryStringQuery("future:[now/D TO now+2M/d]").lenient(false)).get());
assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(e.toString(), containsString("unit [D] not supported for date math"));
}
use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.
the class MoreExpressionTests method testStringSpecialValueVariable.
public void testStringSpecialValueVariable() throws Exception {
// i.e. expression script for term aggregations, which is not allowed
assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", "text", "type=keyword").get());
ensureGreen("test");
indexRandom(true, client().prepareIndex("test", "doc", "1").setSource("text", "hello"), client().prepareIndex("test", "doc", "2").setSource("text", "goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello"));
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.matchAllQuery()).addAggregation(AggregationBuilders.terms("term_agg").field("text").script(new Script(ScriptType.INLINE, ExpressionScriptEngineService.NAME, "_value", Collections.emptyMap())));
String message;
try {
// shards that don't have docs with the "text" field will not fail,
// so we may or may not get a total failure
SearchResponse rsp = req.get();
// at least the shards containing the docs should have failed
assertThat(rsp.getShardFailures().length, greaterThan(0));
message = rsp.getShardFailures()[0].reason();
} catch (SearchPhaseExecutionException e) {
message = e.toString();
}
assertThat(message + "should have contained ScriptException", message.contains("ScriptException"), equalTo(true));
assertThat(message + "should have contained text variable error", message.contains("text variable"), equalTo(true));
}
Aggregations