Search in sources :

Example 6 with SearchPhaseExecutionException

use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.

the class FunctionScoreFieldValueIT method testFieldValueFactor.

public void testFieldValueFactor() throws IOException {
    assertAcked(prepareCreate("test").addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", randomFrom(new String[] { "short", "float", "long", "integer", "double" })).endObject().startObject("body").field("type", "text").endObject().endObject().endObject().endObject()).get());
    client().prepareIndex("test", "type1", "1").setSource("test", 5, "body", "foo").get();
    client().prepareIndex("test", "type1", "2").setSource("test", 17, "body", "foo").get();
    client().prepareIndex("test", "type1", "3").setSource("body", "bar").get();
    refresh();
    // document 2 scores higher because 17 > 5
    SearchResponse response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(simpleQueryStringQuery("foo"), fieldValueFactorFunction("test"))).get();
    assertOrderedSearchHits(response, "2", "1");
    // try again, but this time explicitly use the do-nothing modifier
    response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(simpleQueryStringQuery("foo"), fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.NONE))).get();
    assertOrderedSearchHits(response, "2", "1");
    // document 1 scores higher because 1/5 > 1/17
    response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(simpleQueryStringQuery("foo"), fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL))).get();
    assertOrderedSearchHits(response, "1", "2");
    // doc 3 doesn't have a "test" field, so an exception will be thrown
    try {
        response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(matchAllQuery(), fieldValueFactorFunction("test"))).get();
        assertFailures(response);
    } catch (SearchPhaseExecutionException e) {
    // We are expecting an exception, because 3 has no field
    }
    // doc 3 doesn't have a "test" field but we're defaulting it to 100 so it should be last
    response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(matchAllQuery(), fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL).missing(100))).get();
    assertOrderedSearchHits(response, "1", "2", "3");
    // field is not mapped but we're defaulting it to 100 so all documents should have the same score
    response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(matchAllQuery(), fieldValueFactorFunction("notmapped").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL).missing(100))).get();
    assertEquals(response.getHits().getAt(0).getScore(), response.getHits().getAt(2).getScore(), 0);
    // n divided by 0 is infinity, which should provoke an exception.
    try {
        response = client().prepareSearch("test").setExplain(randomBoolean()).setQuery(functionScoreQuery(simpleQueryStringQuery("foo"), fieldValueFactorFunction("test").modifier(FieldValueFactorFunction.Modifier.RECIPROCAL).factor(0))).get();
        assertFailures(response);
    } catch (SearchPhaseExecutionException e) {
    // This is fine, the query will throw an exception if executed
    // locally, instead of just having failures
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 7 with SearchPhaseExecutionException

use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.

the class SimpleSearchIT method assertRescoreWindowFails.

private void assertRescoreWindowFails(int windowSize) {
    SearchRequestBuilder search = client().prepareSearch("idx").addRescorer(new QueryRescorerBuilder(matchAllQuery()).windowSize(windowSize));
    SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> search.get());
    assertThat(e.toString(), containsString("Rescore window [" + windowSize + "] is too large. It must " + "be less than [" + IndexSettings.MAX_RESCORE_WINDOW_SETTING.get(Settings.EMPTY)));
    assertThat(e.toString(), containsString("This limit can be set by changing the [" + IndexSettings.MAX_RESCORE_WINDOW_SETTING.getKey() + "] index level setting."));
}
Also used : QueryRescorerBuilder(org.elasticsearch.search.rescore.QueryRescorerBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException)

Example 8 with SearchPhaseExecutionException

use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.

the class SimpleSearchIT method assertWindowFails.

private void assertWindowFails(SearchRequestBuilder search) {
    SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> search.get());
    assertThat(e.toString(), containsString("Result window is too large, from + size must be less than or equal to: [" + IndexSettings.MAX_RESULT_WINDOW_SETTING.get(Settings.EMPTY)));
    assertThat(e.toString(), containsString("See the scroll api for a more efficient way to request large data sets"));
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException)

Example 9 with SearchPhaseExecutionException

use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.

the class SearchSliceIT method testInvalidQuery.

public void testInvalidQuery() throws Exception {
    setupIndex(false);
    SearchPhaseExecutionException exc = expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setQuery(matchAllQuery()).slice(new SliceBuilder("invalid_random_int", 0, 10)).get());
    Throwable rootCause = findRootCause(exc);
    assertThat(rootCause.getClass(), equalTo(SearchContextException.class));
    assertThat(rootCause.getMessage(), equalTo("`slice` cannot be used outside of a scroll context"));
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchContextException(org.elasticsearch.search.SearchContextException)

Example 10 with SearchPhaseExecutionException

use of org.elasticsearch.action.search.SearchPhaseExecutionException in project elasticsearch by elastic.

the class SuggestSearchIT method testSuggestAcrossMultipleIndices.

// see #3196
public void testSuggestAcrossMultipleIndices() throws IOException {
    createIndex("test");
    ensureGreen();
    index("test", "type1", "1", "text", "abcd");
    index("test", "type1", "2", "text", "aacd");
    index("test", "type1", "3", "text", "abbd");
    index("test", "type1", "4", "text", "abcc");
    refresh();
    TermSuggestionBuilder termSuggest = termSuggestion("text").suggestMode(// Always, otherwise the results can vary between requests.
    SuggestMode.ALWAYS).text("abcd");
    logger.info("--> run suggestions with one index");
    searchSuggest("test", termSuggest);
    createIndex("test_1");
    ensureGreen();
    index("test_1", "type1", "1", "text", "ab cd");
    index("test_1", "type1", "2", "text", "aa cd");
    index("test_1", "type1", "3", "text", "ab bd");
    index("test_1", "type1", "4", "text", "ab cc");
    refresh();
    termSuggest = termSuggestion("text").suggestMode(// Always, otherwise the results can vary between requests.
    SuggestMode.ALWAYS).text("ab cd").minWordLength(1);
    logger.info("--> run suggestions with two indices");
    searchSuggest("test", termSuggest);
    XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("text").field("type", "text").field("analyzer", "keyword").endObject().endObject().endObject().endObject();
    assertAcked(prepareCreate("test_2").addMapping("type1", mapping));
    ensureGreen();
    index("test_2", "type1", "1", "text", "ab cd");
    index("test_2", "type1", "2", "text", "aa cd");
    index("test_2", "type1", "3", "text", "ab bd");
    index("test_2", "type1", "4", "text", "ab cc");
    index("test_2", "type1", "1", "text", "abcd");
    index("test_2", "type1", "2", "text", "aacd");
    index("test_2", "type1", "3", "text", "abbd");
    index("test_2", "type1", "4", "text", "abcc");
    refresh();
    termSuggest = termSuggestion("text").suggestMode(// Always, otherwise the results can vary between requests.
    SuggestMode.ALWAYS).text("ab cd").minWordLength(1);
    logger.info("--> run suggestions with three indices");
    try {
        searchSuggest("test", termSuggest);
        fail(" can not suggest across multiple indices with different analysis chains");
    } catch (SearchPhaseExecutionException ex) {
        assertThat(ex.getCause(), instanceOf(IllegalStateException.class));
        assertThat(ex.getCause().getMessage(), anyOf(endsWith("Suggest entries have different sizes actual [1] expected [2]"), endsWith("Suggest entries have different sizes actual [2] expected [1]")));
    } catch (IllegalStateException ex) {
        assertThat(ex.getMessage(), anyOf(endsWith("Suggest entries have different sizes actual [1] expected [2]"), endsWith("Suggest entries have different sizes actual [2] expected [1]")));
    }
    termSuggest = termSuggestion("text").suggestMode(// Always, otherwise the results can vary between requests.
    SuggestMode.ALWAYS).text("ABCD").minWordLength(1);
    logger.info("--> run suggestions with four indices");
    try {
        searchSuggest("test", termSuggest);
        fail(" can not suggest across multiple indices with different analysis chains");
    } catch (SearchPhaseExecutionException ex) {
        assertThat(ex.getCause(), instanceOf(IllegalStateException.class));
        assertThat(ex.getCause().getMessage(), anyOf(endsWith("Suggest entries have different text actual [ABCD] expected [abcd]"), endsWith("Suggest entries have different text actual [abcd] expected [ABCD]")));
    } catch (IllegalStateException ex) {
        assertThat(ex.getMessage(), anyOf(endsWith("Suggest entries have different text actual [ABCD] expected [abcd]"), endsWith("Suggest entries have different text actual [abcd] expected [ABCD]")));
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) TermSuggestionBuilder(org.elasticsearch.search.suggest.term.TermSuggestionBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

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