From d8880f29069202c2511f04757458c3bddaf46aed Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 15 Apr 2014 18:50:19 +0200 Subject: [PATCH] Fail a DFS_QUERY_THEN_FETCH request if all shards failed the QUERY phase. Today, if some shards pass the DFS phase but all of them fail the QUERY phase, the response will only consist of failed shards. We should throw an exception instead in order to be consistent with the QUERY_THEN_FETCH type. --- .../type/TransportSearchDfsQueryThenFetchAction.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java index b168a40ab46..802333338da 100644 --- a/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java +++ b/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java @@ -22,10 +22,7 @@ package org.elasticsearch.action.search.type; import com.carrotsearch.hppc.IntArrayList; import org.apache.lucene.search.ScoreDoc; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.search.ReduceSearchPhaseException; -import org.elasticsearch.action.search.SearchOperationThreading; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.*; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; @@ -170,7 +167,11 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA this.addShardFailure(shardIndex, dfsResult.shardTarget(), t); successfulOps.decrementAndGet(); if (counter.decrementAndGet() == 0) { - executeFetchPhase(); + if (successfulOps.get() == 0) { + listener.onFailure(new SearchPhaseExecutionException("query", "all shards failed", buildShardFailures())); + } else { + executeFetchPhase(); + } } }