diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index 65cfd35489033..68e911f24f1d3 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -1080,6 +1080,10 @@ private void executeSearch( // No user preference defined in search request - apply cluster service default searchRequest.allowPartialSearchResults(searchService.defaultAllowPartialSearchResults()); } + if (searchRequest.ignoreUnavailable() == null) { + // No user preference defined in search request - apply cluster service default + searchRequest.ignoreUnavailable(searchService.defaultIgnoreUnavailable()); + } if (searchRequest.isSuggestOnly()) { // disable request cache if we have only suggest searchRequest.requestCache(false); diff --git a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java index fd352b33e87fa..07326cce7c4d7 100644 --- a/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/ClusterSettings.java @@ -390,6 +390,7 @@ public void apply(Settings value, Settings current, Settings previous) { ClusterManagerService.CLUSTER_MANAGER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, SearchService.DEFAULT_SEARCH_TIMEOUT_SETTING, SearchService.DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS, + SearchService.DEFAULT_IGNORE_UNAVAILABLE, TransportSearchAction.SHARD_COUNT_LIMIT_SETTING, TransportSearchAction.SEARCH_CANCEL_AFTER_TIME_INTERVAL_SETTING, TransportSearchAction.SEARCH_QUERY_METRICS_ENABLED_SETTING, diff --git a/server/src/main/java/org/opensearch/search/SearchService.java b/server/src/main/java/org/opensearch/search/SearchService.java index 6b3620e65a271..894b54858e4f5 100644 --- a/server/src/main/java/org/opensearch/search/SearchService.java +++ b/server/src/main/java/org/opensearch/search/SearchService.java @@ -230,6 +230,14 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv Property.NodeScope ); + // Keeping the default value to maintain existing behaviour + public static final Setting DEFAULT_IGNORE_UNAVAILABLE = Setting.boolSetting( + "search.default_ignore_unavailable", + false, + Property.Dynamic, + Property.NodeScope + ); + public static final Setting MAX_OPEN_SCROLL_CONTEXT = Setting.intSetting( "search.max_open_scroll_context", 500, @@ -312,6 +320,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv private volatile boolean defaultAllowPartialSearchResults; + private volatile boolean defaultIgnoreUnavailable; + private volatile boolean lowLevelCancellation; private volatile int maxOpenScrollContext; @@ -381,6 +391,10 @@ public SearchService( clusterService.getClusterSettings() .addSettingsUpdateConsumer(DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS, this::setDefaultAllowPartialSearchResults); + defaultIgnoreUnavailable = DEFAULT_IGNORE_UNAVAILABLE.get(settings); + clusterService.getClusterSettings() + .addSettingsUpdateConsumer(DEFAULT_IGNORE_UNAVAILABLE, this::setDefaultIgnoreUnavailable); + maxOpenScrollContext = MAX_OPEN_SCROLL_CONTEXT.get(settings); clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_OPEN_SCROLL_CONTEXT, this::setMaxOpenScrollContext); @@ -453,6 +467,14 @@ public boolean defaultAllowPartialSearchResults() { return defaultAllowPartialSearchResults; } + private void setDefaultIgnoreUnavailable(boolean defaultIgnoreUnavailable) { + this.defaultIgnoreUnavailable = defaultIgnoreUnavailable; + } + + public boolean defaultIgnoreUnavailable() { + return defaultIgnoreUnavailable; + } + private void setMaxOpenScrollContext(int maxOpenScrollContext) { this.maxOpenScrollContext = maxOpenScrollContext; }