Skip to content

Commit 6b2dc8e

Browse files
Reuse ensureAliasOrIndexExists
1 parent d1f11d4 commit 6b2dc8e

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -349,31 +349,16 @@ Index[] concreteIndices(Context context, String... indexExpressions) {
349349
final Set<Index> concreteIndices = Sets.newLinkedHashSetWithExpectedSize(expressions.size());
350350
final SortedMap<String, IndexAbstraction> indicesLookup = context.state.metadata().getIndicesLookup();
351351
for (String expression : expressions) {
352+
if (options.ignoreUnavailable() == false) {
353+
ensureAliasOrIndexExists(context, expression);
354+
}
352355
IndexAbstraction indexAbstraction = indicesLookup.get(expression);
353356
if (indexAbstraction == null) {
354-
if (options.ignoreUnavailable() == false) {
355-
assert options.expandWildcardExpressions() == false;
356-
throw notFoundException(expression);
357-
} else {
358-
continue;
359-
}
357+
continue;
360358
} 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;
367360
} 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;
377362
}
378363

379364
if (indexAbstraction.getType() == Type.ALIAS && context.isResolveToWriteIndex()) {
@@ -489,6 +474,24 @@ private static IndexNotFoundException notFoundException(String... indexExpressio
489474
return infe;
490475
}
491476

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+
492495
private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, Index index) {
493496
if (context.systemIndexAccessLevel == SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY
494497
&& context.netNewSystemIndexPredicate.test(index.getName())) {
@@ -1260,22 +1263,6 @@ private static String validateAliasOrIndex(String expression) {
12601263
return expression;
12611264
}
12621265

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-
12791266
private static IndexMetadata.State excludeState(IndicesOptions options) {
12801267
final IndexMetadata.State excludeState;
12811268
if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) {

0 commit comments

Comments
 (0)