@@ -349,31 +349,16 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
349
349
final Set <Index > concreteIndices = Sets .newLinkedHashSetWithExpectedSize (expressions .size ());
350
350
final SortedMap <String , IndexAbstraction > indicesLookup = context .state .metadata ().getIndicesLookup ();
351
351
for (String expression : expressions ) {
352
+ if (options .ignoreUnavailable () == false ) {
353
+ ensureAliasOrIndexExists (context , expression );
354
+ }
352
355
IndexAbstraction indexAbstraction = indicesLookup .get (expression );
353
356
if (indexAbstraction == null ) {
354
- if (options .ignoreUnavailable () == false ) {
355
- assert options .expandWildcardExpressions () == false ;
356
- throw notFoundException (expression );
357
- } else {
358
- continue ;
359
- }
357
+ continue ;
360
358
} else if (indexAbstraction .getType () == Type .ALIAS && context .getOptions ().ignoreAliases ()) {
361
- if (options .ignoreUnavailable () == false ) {
362
- assert options .expandWildcardExpressions () == false ;
363
- throw aliasesNotSupportedException (expression );
364
- } else {
365
- continue ;
366
- }
359
+ continue ;
367
360
} else if (indexAbstraction .isDataStreamRelated () && context .includeDataStreams () == false ) {
368
- if (options .ignoreUnavailable () == false ) {
369
- assert options .expandWildcardExpressions () == false ;
370
- IndexNotFoundException infe = notFoundException (indexExpressions );
371
- // Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded.
372
- infe .addMetadata (EXCLUDED_DATA_STREAMS_KEY , "true" );
373
- throw infe ;
374
- } else {
375
- continue ;
376
- }
361
+ continue ;
377
362
}
378
363
379
364
if (indexAbstraction .getType () == Type .ALIAS && context .isResolveToWriteIndex ()) {
@@ -489,6 +474,24 @@ private static IndexNotFoundException notFoundException(String... indexExpressio
489
474
return infe ;
490
475
}
491
476
477
+ @ Nullable
478
+ private static void ensureAliasOrIndexExists (Context context , String expression ) {
479
+ IndexAbstraction indexAbstraction = context .getState ().getMetadata ().getIndicesLookup ().get (expression );
480
+ if (indexAbstraction == null ) {
481
+ throw notFoundException (expression );
482
+ }
483
+ // treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
484
+ if (indexAbstraction .getType () == Type .ALIAS && context .getOptions ().ignoreAliases ()) {
485
+ throw aliasesNotSupportedException (expression );
486
+ }
487
+ if (indexAbstraction .isDataStreamRelated () && context .includeDataStreams () == false ) {
488
+ IndexNotFoundException infe = notFoundException (expression );
489
+ // Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded.
490
+ infe .addMetadata (EXCLUDED_DATA_STREAMS_KEY , "true" );
491
+ throw infe ;
492
+ }
493
+ }
494
+
492
495
private static boolean shouldTrackConcreteIndex (Context context , IndicesOptions options , Index index ) {
493
496
if (context .systemIndexAccessLevel == SystemIndexAccessLevel .BACKWARDS_COMPATIBLE_ONLY
494
497
&& context .netNewSystemIndexPredicate .test (index .getName ())) {
@@ -1260,22 +1263,6 @@ private static String validateAliasOrIndex(String expression) {
1260
1263
return expression ;
1261
1264
}
1262
1265
1263
- @ Nullable
1264
- private static void ensureAliasOrIndexExists (Context context , String expression ) {
1265
- final IndicesOptions options = context .getOptions ();
1266
- IndexAbstraction indexAbstraction = context .getState ().getMetadata ().getIndicesLookup ().get (expression );
1267
- if (indexAbstraction == null ) {
1268
- throw notFoundException (expression );
1269
- }
1270
- // treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api)
1271
- if (indexAbstraction .getType () == Type .ALIAS && options .ignoreAliases ()) {
1272
- throw aliasesNotSupportedException (expression );
1273
- }
1274
- if (indexAbstraction .isDataStreamRelated () && context .includeDataStreams () == false ) {
1275
- throw notFoundException (expression );
1276
- }
1277
- }
1278
-
1279
1266
private static IndexMetadata .State excludeState (IndicesOptions options ) {
1280
1267
final IndexMetadata .State excludeState ;
1281
1268
if (options .expandWildcardsOpen () && options .expandWildcardsClosed ()) {
0 commit comments