Search in sources :

Example 1 with Graphs

use of org.graylog2.utilities.Graphs in project graylog2-server by Graylog2.

the class JestUtils method checkForFailedShards.

public static Optional<ElasticsearchException> checkForFailedShards(JestResult result) {
    // unwrap shard failure due to non-numeric mapping. this happens when searching across index sets
    // if at least one of the index sets comes back with a result, the overall result will have the aggregation
    // but not considered failed entirely. however, if one shard has the error, we will refuse to respond
    // otherwise we would be showing empty graphs for non-numeric fields.
    final JsonNode shards = result.getJsonObject().path("_shards");
    final double failedShards = shards.path("failed").asDouble();
    if (failedShards > 0) {
        final List<String> errors = StreamSupport.stream(shards.path("failures").spliterator(), false).map(failure -> failure.path("reason").path("reason").asText()).filter(s -> !s.isEmpty()).collect(Collectors.toList());
        final List<String> nonNumericFieldErrors = errors.stream().filter(error -> error.startsWith("Expected numeric type on field")).collect(Collectors.toList());
        if (!nonNumericFieldErrors.isEmpty()) {
            return Optional.of(new FieldTypeException("Unable to perform search query: ", deduplicateErrors(nonNumericFieldErrors)));
        }
        return Optional.of(new ElasticsearchException("Unable to perform search query: ", deduplicateErrors(errors)));
    }
    return Optional.empty();
}
Also used : IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) MasterNotDiscoveredException(org.graylog2.indexer.MasterNotDiscoveredException) QueryParsingException(org.graylog2.indexer.QueryParsingException) JestHttpClient(io.searchbox.client.http.JestHttpClient) IOException(java.io.IOException) JestResult(io.searchbox.client.JestResult) RequestConfig(org.apache.http.client.config.RequestConfig) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) FieldTypeException(org.graylog2.indexer.FieldTypeException) ArrayList(java.util.ArrayList) JestClient(io.searchbox.client.JestClient) List(java.util.List) Action(io.searchbox.action.Action) Matcher(java.util.regex.Matcher) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) InvalidWriteTargetException(org.graylog2.indexer.InvalidWriteTargetException) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) FieldTypeException(org.graylog2.indexer.FieldTypeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Action (io.searchbox.action.Action)1 JestClient (io.searchbox.client.JestClient)1 JestResult (io.searchbox.client.JestResult)1 JestHttpClient (io.searchbox.client.http.JestHttpClient)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 ElasticsearchException (org.graylog2.indexer.ElasticsearchException)1 FieldTypeException (org.graylog2.indexer.FieldTypeException)1 IndexNotFoundException (org.graylog2.indexer.IndexNotFoundException)1 InvalidWriteTargetException (org.graylog2.indexer.InvalidWriteTargetException)1