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();
}
Aggregations