diff --git a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java index 0520a4a7aecec..c665cbdb30a59 100644 --- a/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java @@ -425,8 +425,10 @@ public final void executeNextPhase(SearchPhase currentPhase, SearchPhase nextPha currentPhase.getName() ); } - onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null); - return; + if (!request.getIgnoreUnavailableShards()) { + onPhaseFailure(currentPhase, "Partial shards failure (" + discrepancy + " shards unavailable)", null); + return; + } } } if (logger.isTraceEnabled()) { diff --git a/server/src/main/java/org/opensearch/action/search/SearchRequest.java b/server/src/main/java/org/opensearch/action/search/SearchRequest.java index 3b8a6937815aa..c6fea74b2e041 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchRequest.java +++ b/server/src/main/java/org/opensearch/action/search/SearchRequest.java @@ -102,6 +102,8 @@ public class SearchRequest extends ActionRequest implements IndicesRequest.Repla private Boolean allowPartialSearchResults; + private Boolean ignoreUnavailableShards; + private Scroll scroll; private int batchedReduceSize = DEFAULT_BATCHED_REDUCE_SIZE; @@ -198,6 +200,7 @@ private SearchRequest( boolean finalReduce ) { this.allowPartialSearchResults = searchRequest.allowPartialSearchResults; + this.ignoreUnavailableShards = searchRequest.ignoreUnavailableShards; this.batchedReduceSize = searchRequest.batchedReduceSize; this.ccsMinimizeRoundtrips = searchRequest.ccsMinimizeRoundtrips; this.indices = indices; @@ -246,6 +249,9 @@ public SearchRequest(StreamInput in) throws IOException { maxConcurrentShardRequests = in.readVInt(); preFilterShardSize = in.readOptionalVInt(); allowPartialSearchResults = in.readOptionalBoolean(); + if (in.getVersion().onOrAfter(Version.V_2_14_0)) { + ignoreUnavailableShards = in.readOptionalBoolean(); + } localClusterAlias = in.readOptionalString(); if (localClusterAlias != null) { absoluteStartMillis = in.readVLong(); @@ -283,6 +289,9 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVInt(maxConcurrentShardRequests); out.writeOptionalVInt(preFilterShardSize); out.writeOptionalBoolean(allowPartialSearchResults); + if (out.getVersion().onOrAfter(Version.V_2_14_0)) { + out.writeOptionalBoolean(ignoreUnavailableShards); + } out.writeOptionalString(localClusterAlias); if (localClusterAlias != null) { out.writeVLong(absoluteStartMillis); @@ -567,6 +576,15 @@ public Boolean allowPartialSearchResults() { return this.allowPartialSearchResults; } + public SearchRequest ignoreUnavailableShards(boolean ignoreUnavailableShards) { + this.ignoreUnavailableShards = ignoreUnavailableShards; + return this; + } + + public Boolean getIgnoreUnavailableShards() { + return this.ignoreUnavailableShards; + } + /** * Sets the number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection * mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large. @@ -747,6 +765,7 @@ public boolean equals(Object o) { && Objects.equals(preFilterShardSize, that.preFilterShardSize) && Objects.equals(indicesOptions, that.indicesOptions) && Objects.equals(allowPartialSearchResults, that.allowPartialSearchResults) + && Objects.equals(ignoreUnavailableShards, that.ignoreUnavailableShards) && Objects.equals(localClusterAlias, that.localClusterAlias) && absoluteStartMillis == that.absoluteStartMillis && ccsMinimizeRoundtrips == that.ccsMinimizeRoundtrips @@ -770,6 +789,7 @@ public int hashCode() { maxConcurrentShardRequests, preFilterShardSize, allowPartialSearchResults, + ignoreUnavailableShards, localClusterAlias, absoluteStartMillis, ccsMinimizeRoundtrips, @@ -805,6 +825,8 @@ public String toString() { + preFilterShardSize + ", allowPartialSearchResults=" + allowPartialSearchResults + + ", ignoreUnavailableShards=" + + ignoreUnavailableShards + ", localClusterAlias=" + localClusterAlias + ", getOrCreateAbsoluteStartMillis=" diff --git a/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java index 80dc34c4d5d68..2f2095c610da7 100644 --- a/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/opensearch/rest/action/search/RestSearchAction.java @@ -183,6 +183,11 @@ public static void parseSearchRequest( searchRequest.allowPartialSearchResults(request.paramAsBoolean("allow_partial_search_results", null)); } + if (request.hasParam("ignore_unavailable_shards")) { + // only set if we have the parameter passed to override the cluster-level default + searchRequest.ignoreUnavailableShards(request.paramAsBoolean("ignore_unavailable_shards", null)); + } + if (request.hasParam("phase_took")) { // only set if we have the parameter passed to override the cluster-level default // else phaseTook = null