diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java index 51cb9b35becb1..4289c92339513 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlCCSUtils.java @@ -100,6 +100,7 @@ static boolean returnSuccessWithEmptyResult(EsqlExecutionInfo executionInfo, Exc return false; } + // On disconnect error, check whether all remotes are marked as skip_unavailable. if (e instanceof NoClustersToSearchException || ExceptionsHelper.isRemoteUnavailableException(e)) { for (String clusterAlias : executionInfo.clusterAliases()) { if (executionInfo.isSkipUnavailable(clusterAlias) == false @@ -109,6 +110,12 @@ static boolean returnSuccessWithEmptyResult(EsqlExecutionInfo executionInfo, Exc } return true; } + + // If all clusters are skippable remotes, then we can return an empty result. + if (executionInfo.clusterAliases().stream().allMatch(executionInfo::isSkipUnavailable)) { + return true; + } + return false; }