Search in sources :

Example 21 with SearchPhaseExecutionException

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]"));
}
Also used : RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ParsingException(org.elasticsearch.common.ParsingException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) Index(org.elasticsearch.index.Index) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest)

Example 22 with SearchPhaseExecutionException

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"));
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) Scroll(org.elasticsearch.search.Scroll)

Example 23 with SearchPhaseExecutionException

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);
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 24 with SearchPhaseExecutionException

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"));
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime(org.joda.time.DateTime) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 25 with SearchPhaseExecutionException

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));
}
Also used : Script(org.elasticsearch.script.Script) PipelineAggregatorBuilders.bucketScript(org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.bucketScript) CompiledScript(org.elasticsearch.script.CompiledScript) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)42 SearchResponse (org.elasticsearch.action.search.SearchResponse)17 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)10 Timed (com.codahale.metrics.annotation.Timed)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 IOException (java.io.IOException)6 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)6 ArrayList (java.util.ArrayList)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)4 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)4 TimeValue (org.elasticsearch.common.unit.TimeValue)4 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)4 HashMap (java.util.HashMap)2 List (java.util.List)2