2121import java .util .List ;
2222
2323import static org .elasticsearch .transport .RemoteClusterAware .REMOTE_CLUSTER_INDEX_SEPARATOR ;
24+ import static org .elasticsearch .transport .RemoteClusterAware .isRemoteIndexName ;
2425import static org .elasticsearch .xpack .esql .core .util .StringUtils .EXCLUSION ;
2526import static org .elasticsearch .xpack .esql .core .util .StringUtils .WILDCARD ;
2627import static org .elasticsearch .xpack .esql .parser .ParserUtils .source ;
@@ -61,11 +62,14 @@ public String visitIndexPattern(List<EsqlBaseParser.IndexPatternContext> ctx) {
6162 Holder <Boolean > hasSeenStar = new Holder <>(false );
6263 ctx .forEach (c -> {
6364 String indexPattern = visitIndexString (c .indexString ());
64- hasSeenStar .set (indexPattern .contains (WILDCARD ) || hasSeenStar .get ());
65- validateIndexPattern (indexPattern , c , hasSeenStar .get ());
66- patterns .add (
67- c .clusterString () != null ? c .clusterString ().getText () + REMOTE_CLUSTER_INDEX_SEPARATOR + indexPattern : indexPattern
68- );
65+ String clusterString = c .clusterString () != null ? c .clusterString ().getText () : null ;
66+ // skip validating index on remote cluster, because the behavior of remote cluster is not consistent with local cluster
67+ // For example, invalid#index is an invalid index name, however FROM *:invalid#index does not return an error
68+ if (clusterString == null ) {
69+ hasSeenStar .set (indexPattern .contains (WILDCARD ) || hasSeenStar .get ());
70+ validateIndexPattern (indexPattern , c , hasSeenStar .get ());
71+ }
72+ patterns .add (clusterString != null ? clusterString + REMOTE_CLUSTER_INDEX_SEPARATOR + indexPattern : indexPattern );
6973 });
7074 return Strings .collectionToDelimitedString (patterns , "," );
7175 }
@@ -75,6 +79,9 @@ private static void validateIndexPattern(String indexPattern, EsqlBaseParser.Ind
7579 String [] indices = indexPattern .split ("," );
7680 boolean hasExclusion = false ;
7781 for (String index : indices ) {
82+ if (isRemoteIndexName (index )) { // skip the validation if there is remote cluster
83+ continue ;
84+ }
7885 hasSeenStar = index .contains (WILDCARD ) || hasSeenStar ;
7986 index = index .replace (WILDCARD , "" ).strip ();
8087 if (index .isBlank ()) {
0 commit comments