Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate a shard failure in a multi-index search to a global search failure #3379

Merged
merged 1 commit into from Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -516,6 +518,18 @@ public HistogramResult fieldHistogram(String query,
} catch (org.elasticsearch.action.search.SearchPhaseExecutionException e) {
throw new FieldTypeException(e);
}
// 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.
if (r.getFailedShards() > 0) {
final Optional<ShardSearchFailure> failure = Arrays.stream(r.getShardFailures())
.filter(shardSearchFailure -> shardSearchFailure.getCause() instanceof IllegalArgumentException)
.findFirst();
if (failure.isPresent()) {
throw new FieldTypeException(failure.get().getCause());
}
}
recordEsMetrics(r, range);

final Filter f = r.getAggregations().get(AGG_FILTER);
Expand Down