77
88package org .elasticsearch .xpack .esql .plugin ;
99
10+ import org .elasticsearch .action .NoShardAvailableActionException ;
1011import org .elasticsearch .action .admin .indices .template .put .TransportPutComposableIndexTemplateAction ;
1112import org .elasticsearch .action .datastreams .CreateDataStreamAction ;
13+ import org .elasticsearch .action .support .ActiveShardCount ;
1214import org .elasticsearch .cluster .block .ClusterBlockException ;
1315import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
1416import org .elasticsearch .cluster .metadata .IndexMetadata ;
2325
2426import java .util .Collection ;
2527import java .util .List ;
28+ import java .util .UUID ;
2629
2730import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
2831import static org .elasticsearch .xpack .esql .action .EsqlQueryRequest .syncEsqlQueryRequest ;
@@ -130,8 +133,8 @@ public void testDoesNotResolveClosedIndex() {
130133 }
131134
132135 public void testHiddenIndices () {
133- assertAcked (client ().admin ().indices ().prepareCreate ("my -index-1" ));
134- indexRandom (true , "my -index-1" , 10 );
136+ assertAcked (client ().admin ().indices ().prepareCreate ("regular -index-1" ));
137+ indexRandom (true , "regular -index-1" , 10 );
135138 assertAcked (
136139 client ().admin ()
137140 .indices ()
@@ -154,6 +157,35 @@ public void testHiddenIndices() {
154157 }
155158 }
156159
160+ public void testUnavailableIndex () {
161+ assertAcked (client ().admin ().indices ().prepareCreate ("available-index-1" ));
162+ indexRandom (true , "available-index-1" , 10 );
163+ assertAcked (
164+ client ().admin ()
165+ .indices ()
166+ .prepareCreate ("unavailable-index-1" )
167+ .setSettings (Settings .builder ().put ("index.routing.allocation.require._name" , UUID .randomUUID ().toString ()))
168+ .setWaitForActiveShards (ActiveShardCount .NONE )
169+ );
170+
171+ expectThrows (
172+ NoShardAvailableActionException .class ,
173+ containsString ("index [unavailable-index-1] has no active shard copy" ),
174+ () -> run (syncEsqlQueryRequest ().query ("FROM unavailable-index-1" ))
175+ );
176+
177+ expectThrows (
178+ NoShardAvailableActionException .class ,
179+ containsString ("index [unavailable-index-1] has no active shard copy" ),
180+ () -> run (syncEsqlQueryRequest ().query ("FROM unavailable-index-1,available-index-1" ))
181+ );
182+ expectThrows (
183+ NoShardAvailableActionException .class ,
184+ containsString ("index [unavailable-index-1] has no active shard copy" ),
185+ () -> run (syncEsqlQueryRequest ().query ("FROM *-index-1" ))
186+ );
187+ }
188+
157189 public void testPartialResolution () {
158190 assertAcked (client ().admin ().indices ().prepareCreate ("index-1" ));
159191 assertAcked (client ().admin ().indices ().prepareCreate ("index-2" ));
0 commit comments