Search in sources :

Example 1 with SearchError

use of org.graylog.plugins.views.search.errors.SearchError in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method deduplicateShardErrorsOnSearchTypeLevel.

@Test
public void deduplicateShardErrorsOnSearchTypeLevel() throws IOException {
    final MultiSearchResponse multiSearchResult = TestMultisearchResponse.fromFixture("errorhandling/failureOnSearchTypeLevel.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(multiSearchResult.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
    final Set<SearchError> errors = queryResult.errors();
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(1);
    assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: " + "\n\nElasticsearch exception [type=query_shard_exception, reason=Failed to parse query [[]].");
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Example 2 with SearchError

use of org.graylog.plugins.views.search.errors.SearchError in project graylog2-server by Graylog2.

the class QueryEngine method execute.

public SearchJob execute(SearchJob searchJob) {
    searchJob.getSearch().queries().forEach(query -> searchJob.addQueryResultFuture(query.id(), // if need be we default to an empty result with a failed state and the wrapped exception
    CompletableFuture.supplyAsync(() -> prepareAndRun(searchJob, query), queryPool).handle((queryResult, throwable) -> {
        if (throwable != null) {
            final Throwable cause = throwable.getCause();
            final SearchError error;
            if (cause instanceof SearchException) {
                error = ((SearchException) cause).error();
            } else {
                error = new QueryError(query, cause);
            }
            LOG.debug("Running query {} failed: {}", query.id(), cause);
            searchJob.addError(error);
            return QueryResult.failedQueryWithError(query, error);
        }
        return queryResult;
    })));
    searchJob.getSearch().queries().forEach(query -> {
        final CompletableFuture<QueryResult> queryResultFuture = searchJob.getQueryResultFuture(query.id());
        if (!queryResultFuture.isDone()) {
            // this is not going to throw an exception, because we will always replace it with a placeholder "FAILED" result above
            final QueryResult result = queryResultFuture.join();
        } else {
            LOG.debug("[{}] Not generating query for query {}", defaultIfEmpty(query.id(), "root"), query);
        }
    });
    LOG.debug("Search job {} executing", searchJob.getId());
    return searchJob.seal();
}
Also used : QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) SearchException(org.graylog.plugins.views.search.errors.SearchException) QueryError(org.graylog.plugins.views.search.errors.QueryError)

Example 3 with SearchError

use of org.graylog.plugins.views.search.errors.SearchError in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method deduplicateNumericShardErrorsOnSearchTypeLevel.

@Test
public void deduplicateNumericShardErrorsOnSearchTypeLevel() throws IOException {
    final MultiSearchResult multiSearchResult = searchResultFromFixture("errorhandling/numericFailureOnSearchTypeLevel.json");
    when(jestClient.execute(any())).thenReturn(multiSearchResult);
    final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
    final Set<SearchError> errors = queryResult.errors();
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(1);
    assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: \n\nExpected numeric type on field [facility], but got [keyword].");
}
Also used : MultiSearchResult(io.searchbox.core.MultiSearchResult) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Example 4 with SearchError

use of org.graylog.plugins.views.search.errors.SearchError in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method deduplicateShardErrorsOnSearchTypeLevel.

@Test
public void deduplicateShardErrorsOnSearchTypeLevel() throws IOException {
    final MultiSearchResult multiSearchResult = searchResultFromFixture("errorhandling/failureOnSearchTypeLevel.json");
    when(jestClient.execute(any())).thenReturn(multiSearchResult);
    final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
    final Set<SearchError> errors = queryResult.errors();
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(1);
    assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: \n\nFailed to parse query [[].");
}
Also used : MultiSearchResult(io.searchbox.core.MultiSearchResult) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Example 5 with SearchError

use of org.graylog.plugins.views.search.errors.SearchError in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method deduplicateNumericShardErrorsOnSearchTypeLevel.

@Test
public void deduplicateNumericShardErrorsOnSearchTypeLevel() throws IOException {
    final MultiSearchResponse multiSearchResult = TestMultisearchResponse.fromFixture("errorhandling/numericFailureOnSearchTypeLevel.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(multiSearchResult.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
    final Set<SearchError> errors = queryResult.errors();
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(1);
    assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: " + "\n\nElasticsearch exception [type=illegal_argument_exception, reason=Expected numeric type on field [facility], but got [keyword]].");
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Aggregations

QueryResult (org.graylog.plugins.views.search.QueryResult)6 SearchError (org.graylog.plugins.views.search.errors.SearchError)6 Test (org.junit.Test)4 MultiSearchResult (io.searchbox.core.MultiSearchResult)2 QueryError (org.graylog.plugins.views.search.errors.QueryError)2 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)2 EventProcessorException (org.graylog.events.processor.EventProcessorException)1 SearchJob (org.graylog.plugins.views.search.SearchJob)1 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)1 EmptyParameterError (org.graylog.plugins.views.search.errors.EmptyParameterError)1 SearchException (org.graylog.plugins.views.search.errors.SearchException)1 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)1