Search in sources :

Example 26 with SearchPhaseExecutionException

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

the class SuggestSearchIT method testPhraseBoundaryCases.

public void testPhraseBoundaryCases() throws IOException, URISyntaxException {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, // to get reliable statistics we should put this all into one shard
    1).put("index.analysis.analyzer.body.tokenizer", "standard").putArray("index.analysis.analyzer.body.filter", "lowercase").put("index.analysis.analyzer.bigram.tokenizer", "standard").putArray("index.analysis.analyzer.bigram.filter", "my_shingle", "lowercase").put("index.analysis.analyzer.ngram.tokenizer", "standard").putArray("index.analysis.analyzer.ngram.filter", "my_shingle2", "lowercase").put("index.analysis.analyzer.myDefAnalyzer.tokenizer", "standard").putArray("index.analysis.analyzer.myDefAnalyzer.filter", "shingle", "lowercase").put("index.analysis.filter.my_shingle.type", "shingle").put("index.analysis.filter.my_shingle.output_unigrams", false).put("index.analysis.filter.my_shingle.min_shingle_size", 2).put("index.analysis.filter.my_shingle.max_shingle_size", 2).put("index.analysis.filter.my_shingle2.type", "shingle").put("index.analysis.filter.my_shingle2.output_unigrams", true).put("index.analysis.filter.my_shingle2.min_shingle_size", 2).put("index.analysis.filter.my_shingle2.max_shingle_size", 2));
    XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("body").field("type", "text").field("analyzer", "body").endObject().startObject("bigram").field("type", "text").field("analyzer", "bigram").endObject().startObject("ngram").field("type", "text").field("analyzer", "ngram").endObject().endObject().endObject().endObject();
    assertAcked(builder.addMapping("type1", mapping));
    ensureGreen();
    String[] strings = new String[] { "Xorr the God-Jewel", "Grog the God-Crusher", "Xorn", "Walter Newell", "Wanda Maximoff", "Captain America", "American Ace", "Wundarr the Aquarian", "Will o' the Wisp", "Xemnu the Titan" };
    for (String line : strings) {
        index("test", "type1", line, "body", line, "bigram", line, "ngram", line);
    }
    refresh();
    NumShards numShards = getNumShards("test");
    // Lets make sure some things throw exceptions
    PhraseSuggestionBuilder phraseSuggestion = phraseSuggestion("bigram").analyzer("body").addCandidateGenerator(candidateGenerator("does_not_exist").minWordLength(1).suggestMode("always")).realWordErrorLikelihood(0.95f).maxErrors(0.5f).size(1);
    phraseSuggestion.clearCandidateGenerators().analyzer(null);
    try {
        searchSuggest("xor the got-jewel", numShards.numPrimaries, Collections.singletonMap("simple_phrase", phraseSuggestion));
        fail("analyzer does only produce ngrams");
    } catch (SearchPhaseExecutionException e) {
    }
    phraseSuggestion.analyzer("bigram");
    try {
        searchSuggest("xor the got-jewel", numShards.numPrimaries, Collections.singletonMap("simple_phrase", phraseSuggestion));
        fail("analyzer does only produce ngrams");
    } catch (SearchPhaseExecutionException e) {
    }
    // Now we'll make sure some things don't
    phraseSuggestion.forceUnigrams(false);
    searchSuggest("xor the got-jewel", 0, Collections.singletonMap("simple_phrase", phraseSuggestion));
    // Field doesn't produce unigrams but the analyzer does
    phraseSuggestion.forceUnigrams(true).analyzer("ngram");
    searchSuggest("xor the got-jewel", 0, Collections.singletonMap("simple_phrase", phraseSuggestion));
    phraseSuggestion = phraseSuggestion("ngram").analyzer("myDefAnalyzer").forceUnigrams(true).realWordErrorLikelihood(0.95f).maxErrors(0.5f).size(1).addCandidateGenerator(candidateGenerator("body").minWordLength(1).suggestMode("always"));
    Suggest suggest = searchSuggest("xor the got-jewel", 0, Collections.singletonMap("simple_phrase", phraseSuggestion));
    // "xorr the god jewel" and and "xorn the god jewel" have identical scores (we are only using unigrams to score), so we tie break by
    // earlier term (xorn):
    assertSuggestion(suggest, 0, "simple_phrase", "xorn the god jewel");
    phraseSuggestion.analyzer(null);
    suggest = searchSuggest("xor the got-jewel", 0, Collections.singletonMap("simple_phrase", phraseSuggestion));
    // In this case xorr has a better score than xorn because we set the field back to the default (my_shingle2) analyzer, so the
    // probability that the term is not in the dictionary but is NOT a misspelling is relatively high in this case compared to the
    // others that have no n-gram with the other terms in the phrase :) you can set this realWorldErrorLikelyhood
    assertSuggestion(suggest, 0, "simple_phrase", "xorr the god jewel");
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) PhraseSuggestionBuilder(org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 27 with SearchPhaseExecutionException

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

the class CompletionSuggestSearchIT method testThatSortingOnCompletionFieldReturnsUsefulException.

public void testThatSortingOnCompletionFieldReturnsUsefulException() throws Exception {
    createIndexAndMapping(completionMappingBuilder);
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().startObject(FIELD).startArray("input").value("Nirvana").endArray().endObject().endObject()).get();
    refresh();
    try {
        client().prepareSearch(INDEX).setTypes(TYPE).addSort(new FieldSortBuilder(FIELD)).execute().actionGet();
        fail("Expected an exception due to trying to sort on completion field, but did not happen");
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.status().getStatus(), is(400));
        assertThat(e.toString(), containsString("Fielddata is not supported on field [" + FIELD + "] of type [completion]"));
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder)

Example 28 with SearchPhaseExecutionException

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

the class CompletionSuggestSearchIT method testIssue5930.

// see #5930
public void testIssue5930() throws IOException {
    assertAcked(client().admin().indices().prepareCreate(INDEX).addMapping(TYPE, jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "completion").endObject().endObject().endObject().endObject()).get());
    String string = "foo bar";
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().field(FIELD, string).endObject()).setRefreshPolicy(IMMEDIATE).get();
    try {
        client().prepareSearch(INDEX).addAggregation(AggregationBuilders.terms("suggest_agg").field(FIELD).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet();
        // Exception must be thrown
        assertFalse(true);
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.toString(), containsString("Fielddata is not supported on field [" + FIELD + "] of type [completion]"));
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 29 with SearchPhaseExecutionException

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

the class ElasticsearchAssertions method assertFailures.

public static void assertFailures(SearchRequestBuilder searchRequestBuilder, RestStatus restStatus, Matcher<String> reasonMatcher) {
    //we can either run into partial or total failures depending on the current number of shards
    try {
        SearchResponse searchResponse = searchRequestBuilder.get();
        assertThat("Expected shard failures, got none", searchResponse.getShardFailures().length, greaterThan(0));
        for (ShardSearchFailure shardSearchFailure : searchResponse.getShardFailures()) {
            assertThat(shardSearchFailure.status(), equalTo(restStatus));
            assertThat(shardSearchFailure.reason(), reasonMatcher);
        }
        assertVersionSerializable(searchResponse);
    } catch (SearchPhaseExecutionException e) {
        assertThat(e.status(), equalTo(restStatus));
        assertThat(e.toString(), reasonMatcher);
        for (ShardSearchFailure shardSearchFailure : e.shardFailures()) {
            assertThat(shardSearchFailure.status(), equalTo(restStatus));
            assertThat(shardSearchFailure.reason(), reasonMatcher);
        }
    } catch (Exception e) {
        fail("SearchPhaseExecutionException expected but got " + e.getClass());
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardOperationFailedException(org.elasticsearch.action.ShardOperationFailedException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 30 with SearchPhaseExecutionException

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

the class SearchCancellationIT method ensureSearchWasCancelled.

private SearchResponse ensureSearchWasCancelled(ListenableActionFuture<SearchResponse> searchResponse) {
    try {
        SearchResponse response = searchResponse.actionGet();
        logger.info("Search response {}", response);
        assertNotEquals("At least one shard should have failed", 0, response.getFailedShards());
        return response;
    } catch (SearchPhaseExecutionException ex) {
        logger.info("All shards failed with", ex);
        return null;
    }
}
Also used : SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

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