|
@@ -335,28 +335,12 @@ public class IndexNameExpressionResolver {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // If only one index is specified then whether we fail a request if an index is missing depends on the allow_no_indices
|
|
|
- // option. At some point we should change this, because there shouldn't be a reason why whether a single index
|
|
|
- // or multiple indices are specified yield different behaviour.
|
|
|
- final boolean failNoIndices = indexExpressions.length == 1
|
|
|
- ? options.allowNoIndices() == false
|
|
|
- : options.ignoreUnavailable() == false;
|
|
|
+
|
|
|
final Collection<String> expressions = resolveExpressions(Arrays.asList(indexExpressions), context);
|
|
|
|
|
|
- if (expressions.isEmpty()) {
|
|
|
+ if (expressions.isEmpty() || (expressions.size() == 1 && expressions.iterator().next().equals(Metadata.ALL))) {
|
|
|
if (options.allowNoIndices() == false) {
|
|
|
- IndexNotFoundException infe;
|
|
|
- if (indexExpressions.length == 1) {
|
|
|
- if (indexExpressions[0].equals(Metadata.ALL)) {
|
|
|
- infe = new IndexNotFoundException("no indices exist", (String) null);
|
|
|
- } else {
|
|
|
- infe = new IndexNotFoundException((String) null);
|
|
|
- }
|
|
|
- } else {
|
|
|
- infe = new IndexNotFoundException((String) null);
|
|
|
- }
|
|
|
- infe.setResources("index_expression", indexExpressions);
|
|
|
- throw infe;
|
|
|
+ throw notFoundException(indexExpressions);
|
|
|
} else {
|
|
|
return Index.EMPTY_ARRAY;
|
|
|
}
|
|
@@ -368,20 +352,15 @@ public class IndexNameExpressionResolver {
|
|
|
for (String expression : expressions) {
|
|
|
IndexAbstraction indexAbstraction = indicesLookup.get(expression);
|
|
|
if (indexAbstraction == null) {
|
|
|
- if (failNoIndices) {
|
|
|
- IndexNotFoundException infe;
|
|
|
- if (expression.equals(Metadata.ALL)) {
|
|
|
- infe = new IndexNotFoundException("no indices exist", expression);
|
|
|
- } else {
|
|
|
- infe = new IndexNotFoundException(expression);
|
|
|
- }
|
|
|
- infe.setResources("index_expression", expression);
|
|
|
- throw infe;
|
|
|
+ if (options.ignoreUnavailable() == false) {
|
|
|
+ assert options.expandWildcardExpressions() == false;
|
|
|
+ throw notFoundException(expression);
|
|
|
} else {
|
|
|
continue;
|
|
|
}
|
|
|
} else if (indexAbstraction.getType() == Type.ALIAS && context.getOptions().ignoreAliases()) {
|
|
|
- if (failNoIndices) {
|
|
|
+ if (options.ignoreUnavailable() == false) {
|
|
|
+ assert options.expandWildcardExpressions() == false;
|
|
|
throw aliasesNotSupportedException(expression);
|
|
|
} else {
|
|
|
continue;
|
|
@@ -436,8 +415,7 @@ public class IndexNameExpressionResolver {
|
|
|
}
|
|
|
|
|
|
if (options.allowNoIndices() == false && concreteIndices.isEmpty()) {
|
|
|
- IndexNotFoundException infe = new IndexNotFoundException((String) null);
|
|
|
- infe.setResources("index_expression", indexExpressions);
|
|
|
+ IndexNotFoundException infe = notFoundException(indexExpressions);
|
|
|
if (excludedDataStreams) {
|
|
|
// Allows callers to handle IndexNotFoundException differently based on whether data streams were excluded.
|
|
|
infe.addMetadata(EXCLUDED_DATA_STREAMS_KEY, "true");
|
|
@@ -448,6 +426,22 @@ public class IndexNameExpressionResolver {
|
|
|
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<Index> concreteIndices) {
|
|
|
final Metadata metadata = context.getState().metadata();
|
|
|
final Predicate<String> systemIndexAccessPredicate = context.getSystemIndexAccessPredicate().negate();
|