diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java
index 69c140a23fb..25554c54555 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/ShardOperationFailedException.java
@@ -21,12 +21,14 @@ package org.elasticsearch.action;
import org.elasticsearch.util.io.stream.Streamable;
+import java.io.Serializable;
+
/**
* An exception indicating that a failure occurred performing an operation on the shard.
*
* @author kimchy (Shay Banon)
*/
-public interface ShardOperationFailedException extends Streamable {
+public interface ShardOperationFailedException extends Streamable, Serializable {
/**
* The index the operation failed on. Might return null if it can't be derived.
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java
index c8cc41afce2..6ea9d508558 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/ReduceSearchPhaseException.java
@@ -19,21 +19,19 @@
package org.elasticsearch.action.search;
-import org.elasticsearch.ElasticSearchException;
-
/**
* A failure during a reduce phase (when receiving results from several shards, and reducing them
* into one or more results and possible actions).
*
* @author kimchy (shay.banon)
*/
-public class ReduceSearchPhaseException extends ElasticSearchException {
+public class ReduceSearchPhaseException extends SearchPhaseExecutionException {
- public ReduceSearchPhaseException(String phaseName, String msg) {
- super("Failed to reduce [" + phaseName + "] " + msg);
+ public ReduceSearchPhaseException(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
+ super(phaseName, "[reduce] " + msg, shardFailures);
}
- public ReduceSearchPhaseException(String phaseName, String msg, Throwable cause) {
- super("Failed to reduce [" + phaseName + "]" + msg, cause);
+ public ReduceSearchPhaseException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) {
+ super(phaseName, "[reduce] " + msg, cause, shardFailures);
}
}
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java
new file mode 100644
index 00000000000..9e4f70cf19b
--- /dev/null
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchPhaseExecutionException.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to Elastic Search and Shay Banon under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. Elastic Search licenses this
+ * file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.elasticsearch.action.search;
+
+import org.elasticsearch.ElasticSearchException;
+
+/**
+ * @author kimchy (shay.banon)
+ */
+public class SearchPhaseExecutionException extends ElasticSearchException {
+
+ private final String phaseName;
+
+ private ShardSearchFailure[] shardFailures;
+
+ public SearchPhaseExecutionException(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
+ super(buildMessage(phaseName, msg, shardFailures));
+ this.phaseName = phaseName;
+ this.shardFailures = shardFailures;
+ }
+
+ public SearchPhaseExecutionException(String phaseName, String msg, Throwable cause, ShardSearchFailure[] shardFailures) {
+ super(buildMessage(phaseName, msg, shardFailures), cause);
+ this.phaseName = phaseName;
+ this.shardFailures = shardFailures;
+ }
+
+ public String phaseName() {
+ return phaseName;
+ }
+
+ public ShardSearchFailure[] shardFailures() {
+ return shardFailures;
+ }
+
+ private static final String buildMessage(String phaseName, String msg, ShardSearchFailure[] shardFailures) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Failed to execute [").append(phaseName).append("] ").append(msg);
+ if (shardFailures != null && shardFailures.length > 0) {
+ sb.append("; shardFailures ");
+ for (ShardSearchFailure shardFailure : shardFailures) {
+ sb.append("{").append(shardFailure.shard()).append(": ").append(shardFailure.reason()).append("}");
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java
index a767ef80937..8b73c304444 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryAndFetchAction.java
@@ -158,7 +158,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc
try {
innerFinishHim();
} catch (Exception e) {
- listener.onFailure(new ReduceSearchPhaseException("query_fetch", "", e));
+ listener.onFailure(new ReduceSearchPhaseException("query_fetch", "", e, buildShardFailures()));
}
}
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java
index e31bd43ddc7..e5b32ca7253 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchDfsQueryThenFetchAction.java
@@ -164,7 +164,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA
try {
innerExecuteFetchPhase();
} catch (Exception e) {
- listener.onFailure(new ReduceSearchPhaseException("query", "", e));
+ listener.onFailure(new ReduceSearchPhaseException("query", "", e, buildShardFailures()));
}
}
@@ -248,7 +248,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA
try {
innerFinishHim();
} catch (Exception e) {
- listener.onFailure(new ReduceSearchPhaseException("fetch", "", e));
+ listener.onFailure(new ReduceSearchPhaseException("fetch", "", e, buildShardFailures()));
}
}
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java
index 4db06e06aad..bde0671e612 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchQueryThenFetchAction.java
@@ -161,7 +161,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi
try {
innerFinishHim();
} catch (Exception e) {
- listener.onFailure(new ReduceSearchPhaseException("fetch", "", e));
+ listener.onFailure(new ReduceSearchPhaseException("fetch", "", e, buildShardFailures()));
}
}
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java
index df2bf78ec1c..77a70d1ac59 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/search/type/TransportSearchTypeAction.java
@@ -194,7 +194,7 @@ public abstract class TransportSearchTypeAction extends BaseAction