diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index 2174b243cec6d..d9164e604b944 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -427,22 +427,6 @@ Index[] concreteIndices(Context context, String... indexExpressions) { return concreteIndices.toArray(Index.EMPTY_ARRAY); } - private IndexNotFoundException notFoundException(String... indexExpressions) { - IndexNotFoundException infe; - if (indexExpressions.length == 1) { - if (indexExpressions[0].equals(Metadata.ALL)) { - infe = new IndexNotFoundException("no indices exist", indexExpressions[0]); - } else { - infe = new IndexNotFoundException(indexExpressions[0]); - } - infe.setResources("index_expression", indexExpressions[0]); - } else { - infe = new IndexNotFoundException((String) null); - infe.setResources("index_expression", indexExpressions); - } - return infe; - } - private void checkSystemIndexAccess(Context context, Set concreteIndices) { final Metadata metadata = context.getState().metadata(); final Predicate systemIndexAccessPredicate = context.getSystemIndexAccessPredicate().negate(); @@ -489,6 +473,22 @@ private void checkSystemIndexAccess(Context context, Set concreteIndices) } } + private static IndexNotFoundException notFoundException(String... indexExpressions) { + IndexNotFoundException infe; + if (indexExpressions != null && indexExpressions.length == 1) { + if (Metadata.ALL.equals(indexExpressions[0])) { + infe = new IndexNotFoundException("no indices exist", indexExpressions[0]); + } else { + infe = new IndexNotFoundException(indexExpressions[0]); + } + infe.setResources("index_or_alias", indexExpressions[0]); + } else { + infe = new IndexNotFoundException((String) null); + infe.setResources("index_expression", indexExpressions); + } + return infe; + } + private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, Index index) { if (context.systemIndexAccessLevel == SystemIndexAccessLevel.BACKWARDS_COMPATIBLE_ONLY && context.netNewSystemIndexPredicate.test(index.getName())) { @@ -1216,7 +1216,7 @@ private static Collection innerResolve(Context context, List exp matchingOpenClosedNames.forEachOrdered(result::add); } if (emptyWildcardExpansion.get()) { - throw indexNotFoundException(expression); + throw notFoundException(expression); } } else { if (isExclusion) { @@ -1248,7 +1248,7 @@ private static Collection innerResolve(Context context, List exp private static String validateAliasOrIndex(String expression) { if (Strings.isEmpty(expression)) { - throw indexNotFoundException(expression); + throw notFoundException(expression); } // Expressions can not start with an underscore. This is reserved for APIs. If the check gets here, the API // does not exist and the path is interpreted as an expression. If the expression begins with an underscore, @@ -1265,23 +1265,17 @@ private static void ensureAliasOrIndexExists(Context context, String expression) final IndicesOptions options = context.getOptions(); IndexAbstraction indexAbstraction = context.getState().getMetadata().getIndicesLookup().get(expression); if (indexAbstraction == null) { - throw indexNotFoundException(expression); + throw notFoundException(expression); } // treat aliases as unavailable indices when ignoreAliases is set to true (e.g. delete index and update aliases api) if (indexAbstraction.getType() == Type.ALIAS && options.ignoreAliases()) { throw aliasesNotSupportedException(expression); } if (indexAbstraction.isDataStreamRelated() && context.includeDataStreams() == false) { - throw indexNotFoundException(expression); + throw notFoundException(expression); } } - private static IndexNotFoundException indexNotFoundException(String expression) { - IndexNotFoundException infe = new IndexNotFoundException(expression); - infe.setResources("index_or_alias", expression); - return infe; - } - private static IndexMetadata.State excludeState(IndicesOptions options) { final IndexMetadata.State excludeState; if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) {