1414import org .elasticsearch .action .support .IndicesOptions ;
1515import org .elasticsearch .cluster .ClusterState ;
1616import org .elasticsearch .cluster .metadata .IndexAbstraction .Type ;
17- import org .elasticsearch .core .Nullable ;
1817import org .elasticsearch .common .Strings ;
1918import org .elasticsearch .common .collect .ImmutableOpenMap ;
2019import org .elasticsearch .common .logging .DeprecationCategory ;
2625import org .elasticsearch .common .util .CollectionUtils ;
2726import org .elasticsearch .common .util .concurrent .ThreadContext ;
2827import org .elasticsearch .common .util .set .Sets ;
28+ import org .elasticsearch .core .Nullable ;
2929import org .elasticsearch .index .Index ;
3030import org .elasticsearch .index .IndexNotFoundException ;
3131import org .elasticsearch .indices .IndexClosedException ;
@@ -112,7 +112,7 @@ public Index[] concreteIndices(ClusterState state, IndicesRequest request) {
112112 * provided indices options in the context don't allow such a case, or if the final result of the indices resolution
113113 * contains no indices and the indices options in the context don't allow such a case.
114114 * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
115- * indices options in the context don't allow such a case.
115+ * indices options in the context don't allow such a case; if a remote index is requested .
116116 */
117117 public String [] concreteIndexNames (ClusterState state , IndicesOptions options , String ... indexExpressions ) {
118118 Context context = new Context (state , options , getSystemIndexAccessLevel (),
@@ -167,7 +167,7 @@ public List<String> dataStreamNames(ClusterState state, IndicesOptions options,
167167 * provided indices options in the context don't allow such a case, or if the final result of the indices resolution
168168 * contains no indices and the indices options in the context don't allow such a case.
169169 * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
170- * indices options in the context don't allow such a case.
170+ * indices options in the context don't allow such a case; if a remote index is requested .
171171 */
172172 public Index [] concreteIndices (ClusterState state , IndicesOptions options , String ... indexExpressions ) {
173173 return concreteIndices (state , options , false , indexExpressions );
@@ -189,7 +189,7 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, boole
189189 * provided indices options in the context don't allow such a case, or if the final result of the indices resolution
190190 * contains no indices and the indices options in the context don't allow such a case.
191191 * @throws IllegalArgumentException if one of the aliases resolve to multiple indices and the provided
192- * indices options in the context don't allow such a case.
192+ * indices options in the context don't allow such a case; if a remote index is requested .
193193 */
194194 public Index [] concreteIndices (ClusterState state , IndicesRequest request , long startTime ) {
195195 Context context = new Context (state , request .indicesOptions (), startTime , false , false , request .includeDataStreams (), false ,
@@ -207,11 +207,20 @@ String[] concreteIndexNames(Context context, String... indexExpressions) {
207207 }
208208
209209 Index [] concreteIndices (Context context , String ... indexExpressions ) {
210+ Metadata metadata = context .getState ().metadata ();
211+ IndicesOptions options = context .getOptions ();
210212 if (indexExpressions == null || indexExpressions .length == 0 ) {
211213 indexExpressions = new String []{Metadata .ALL };
214+ } else {
215+ if (options .ignoreUnavailable () == false ) {
216+ List <String > crossClusterIndices = Arrays .stream (indexExpressions )
217+ .filter (index -> index .contains (":" )).collect (Collectors .toList ());
218+ if (crossClusterIndices .size () > 0 ) {
219+ throw new IllegalArgumentException ("Cross-cluster calls are not supported in this context but remote indices " +
220+ "were requested: " + crossClusterIndices );
221+ }
222+ }
212223 }
213- Metadata metadata = context .getState ().metadata ();
214- IndicesOptions options = context .getOptions ();
215224 // If only one index is specified then whether we fail a request if an index is missing depends on the allow_no_indices
216225 // option. At some point we should change this, because there shouldn't be a reason why whether a single index
217226 // or multiple indices are specified yield different behaviour.
@@ -396,7 +405,7 @@ private static IllegalArgumentException aliasesNotSupportedException(String expr
396405 * @param state the cluster state containing all the data to resolve to expression to a concrete index
397406 * @param request The request that defines how the an alias or an index need to be resolved to a concrete index
398407 * and the expression that can be resolved to an alias or an index name.
399- * @throws IllegalArgumentException if the index resolution lead to more than one index
408+ * @throws IllegalArgumentException if the index resolution returns more than one index; if a remote index is requested.
400409 * @return the concrete index obtained as a result of the index resolution
401410 */
402411 public Index concreteSingleIndex (ClusterState state , IndicesRequest request ) {
@@ -433,7 +442,8 @@ public Index concreteWriteIndex(ClusterState state, IndicesRequest request) {
433442 * @param index index that can be resolved to alias or index name.
434443 * @param allowNoIndices whether to allow resolve to no index
435444 * @param includeDataStreams Whether data streams should be included in the evaluation.
436- * @throws IllegalArgumentException if the index resolution does not lead to an index, or leads to more than one index
445+ * @throws IllegalArgumentException if the index resolution does not lead to an index, or leads to more than one index, as well as
446+ * if a remote index is requested.
437447 * @return the write index obtained as a result of the index resolution or null if no index
438448 */
439449 public Index concreteWriteIndex (ClusterState state , IndicesOptions options , String index , boolean allowNoIndices ,
0 commit comments