@@ -2441,6 +2441,118 @@ private ClusterState systemIndexTestClusterState() {
24412441 return ClusterState .builder (new ClusterName ("_name" )).metadata (mdBuilder ).build ();
24422442 }
24432443
2444+ public void testRemoteIndex () {
2445+ Metadata .Builder mdBuilder = Metadata .builder ();
2446+ ClusterState state = ClusterState .builder (new ClusterName ("_name" )).metadata (mdBuilder ).build ();
2447+
2448+ {
2449+ IndicesOptions options = IndicesOptions .fromOptions (false , randomBoolean (), randomBoolean (), randomBoolean (), randomBoolean ());
2450+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2451+ state , options , SystemIndexAccessLevel .NONE );
2452+ IllegalArgumentException iae = expectThrows (IllegalArgumentException .class ,
2453+ () -> indexNameExpressionResolver .concreteIndexNames (context , "cluster:index" , "local" ));
2454+ assertEquals ("Cross-cluster calls are not supported in this context but remote indices were requested: [cluster:index]" ,
2455+ iae .getMessage ());
2456+ }
2457+ {
2458+ IndicesOptions options = IndicesOptions .fromOptions (false , randomBoolean (), randomBoolean (), randomBoolean (), randomBoolean ());
2459+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2460+ state , options , SystemIndexAccessLevel .NONE );
2461+ IllegalArgumentException iae = expectThrows (IllegalArgumentException .class ,
2462+ () -> indexNameExpressionResolver .concreteIndexNames (context , "cluster:*" , "local" ));
2463+ assertEquals ("Cross-cluster calls are not supported in this context but remote indices were requested: [cluster:*]" ,
2464+ iae .getMessage ());
2465+ }
2466+ {
2467+ IndicesOptions options = IndicesOptions .fromOptions (false , randomBoolean (), randomBoolean (), randomBoolean (), randomBoolean ());
2468+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2469+ state , options , SystemIndexAccessLevel .NONE );
2470+ IllegalArgumentException iae = expectThrows (IllegalArgumentException .class ,
2471+ () -> indexNameExpressionResolver .concreteIndexNames (context , "cluster:i*" , "local" ));
2472+ assertEquals ("Cross-cluster calls are not supported in this context but remote indices were requested: [cluster:i*]" ,
2473+ iae .getMessage ());
2474+ }
2475+ {
2476+ IndicesOptions options = IndicesOptions .fromOptions (true , true , randomBoolean (), randomBoolean (), randomBoolean ());
2477+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2478+ state , options , SystemIndexAccessLevel .NONE );
2479+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:index" , "local" );
2480+ assertEquals (0 , indexNames .length );
2481+ }
2482+ {
2483+ IndicesOptions options = IndicesOptions .fromOptions (true , true , randomBoolean (), randomBoolean (), randomBoolean ());
2484+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2485+ state , options , SystemIndexAccessLevel .NONE );
2486+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:i*" , "local" );
2487+ assertEquals (0 , indexNames .length );
2488+ }
2489+ }
2490+
2491+ public void testColonWithinIndexName () {
2492+ Settings settings = Settings .builder ().build ();
2493+ Metadata .Builder mdBuilder = Metadata .builder ()
2494+ .put (indexBuilder ("cluster:index" , settings ).state (State .OPEN ));
2495+ ClusterState state = ClusterState .builder (new ClusterName ("_name" )).metadata (mdBuilder ).build ();
2496+
2497+ {
2498+ IndicesOptions options = IndicesOptions .fromOptions (randomBoolean (), randomBoolean (),
2499+ randomBoolean (), randomBoolean (), randomBoolean ());
2500+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2501+ state , options , SystemIndexAccessLevel .NONE );
2502+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:index" );
2503+ assertThat (indexNames , arrayContaining ("cluster:index" ));
2504+ }
2505+ //Using wildcards, expand wildcards to open indices: true -> index locally resolved
2506+ {
2507+ IndicesOptions options = IndicesOptions .fromOptions (randomBoolean (), randomBoolean (), true , randomBoolean (), randomBoolean ());
2508+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2509+ state , options , SystemIndexAccessLevel .NONE );
2510+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:*" );
2511+ assertThat (indexNames , arrayContaining ("cluster:index" ));
2512+ }
2513+ {
2514+ IndicesOptions options = IndicesOptions .fromOptions (randomBoolean (), randomBoolean (), true , randomBoolean (), randomBoolean ());
2515+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2516+ state , options , SystemIndexAccessLevel .NONE );
2517+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:in*" );
2518+ assertThat (indexNames , arrayContaining ("cluster:index" ));
2519+ }
2520+ //With wildcards, ignore_unavailable: false, expand wildcards to open indices: false -> error about cross cluster indices
2521+ {
2522+ IndicesOptions options = IndicesOptions .fromOptions (false , randomBoolean (), false , randomBoolean (), randomBoolean ());
2523+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2524+ state , options , SystemIndexAccessLevel .NONE );
2525+ IllegalArgumentException iae = expectThrows (IllegalArgumentException .class ,
2526+ () -> indexNameExpressionResolver .concreteIndexNames (context , "cluster:*" ));
2527+ assertEquals ("Cross-cluster calls are not supported in this context but remote indices were requested: [cluster:*]" ,
2528+ iae .getMessage ());
2529+ }
2530+ {
2531+ IndicesOptions options = IndicesOptions .fromOptions (false , randomBoolean (), false , randomBoolean (), randomBoolean ());
2532+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2533+ state , options , SystemIndexAccessLevel .NONE );
2534+ IllegalArgumentException iae = expectThrows (IllegalArgumentException .class ,
2535+ () -> indexNameExpressionResolver .concreteIndexNames (context , "cluster:in*" ));
2536+ assertEquals ("Cross-cluster calls are not supported in this context but remote indices were requested: [cluster:in*]" ,
2537+ iae .getMessage ());
2538+ }
2539+ //With wildcards: ignore_unavailable: true, allow_no_indices: true, expand wildcards to open indices: false -> empty list of indices
2540+ {
2541+ IndicesOptions options = IndicesOptions .fromOptions (true , true , false , randomBoolean (), randomBoolean ());
2542+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2543+ state , options , SystemIndexAccessLevel .NONE );
2544+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:*" );
2545+ assertEquals (0 , indexNames .length );
2546+ }
2547+ {
2548+ IndicesOptions options = IndicesOptions .fromOptions (true , true , false , randomBoolean (), randomBoolean ());
2549+ IndexNameExpressionResolver .Context context = new IndexNameExpressionResolver .Context (
2550+ state , options , SystemIndexAccessLevel .NONE );
2551+ String [] indexNames = indexNameExpressionResolver .concreteIndexNames (context , "cluster:in*" );
2552+ assertEquals (0 , indexNames .length );
2553+ }
2554+ }
2555+
24442556 private List <String > resolveConcreteIndexNameList (ClusterState state , SearchRequest request ) {
24452557 return Arrays
24462558 .stream (indexNameExpressionResolver .concreteIndices (state , request ))
0 commit comments