Improve error message for absence of indices (#39789)
"no indices exist" has been added to the error message for absence of indices
This commit is contained in:
parent
f2ca45c210
commit
444b4c4136
|
@ -160,7 +160,16 @@ public class IndexNameExpressionResolver {
|
|||
|
||||
if (expressions.isEmpty()) {
|
||||
if (!options.allowNoIndices()) {
|
||||
IndexNotFoundException infe = new IndexNotFoundException((String)null);
|
||||
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;
|
||||
} else {
|
||||
|
@ -173,7 +182,12 @@ public class IndexNameExpressionResolver {
|
|||
AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(expression);
|
||||
if (aliasOrIndex == null ) {
|
||||
if (failNoIndices) {
|
||||
IndexNotFoundException infe = new IndexNotFoundException(expression);
|
||||
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;
|
||||
} else {
|
||||
|
|
|
@ -580,6 +580,25 @@ public class IndexNameExpressionResolverTests extends ESTestCase {
|
|||
assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, new String[]{})),
|
||||
equalTo(newHashSet("kuku", "testXXX")));
|
||||
}
|
||||
public void testConcreteIndicesNoIndicesErrorMessage() {
|
||||
MetaData.Builder mdBuilder = MetaData.builder();
|
||||
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
|
||||
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state,
|
||||
IndicesOptions.fromOptions(false, false, true, true));
|
||||
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class,
|
||||
() -> indexNameExpressionResolver.concreteIndices(context, new String[]{}));
|
||||
assertThat(infe.getMessage(), is("no such index [null] and no indices exist"));
|
||||
}
|
||||
|
||||
public void testConcreteIndicesNoIndicesErrorMessageNoExpand() {
|
||||
MetaData.Builder mdBuilder = MetaData.builder();
|
||||
ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
|
||||
IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state,
|
||||
IndicesOptions.fromOptions(false, false, false, false));
|
||||
IndexNotFoundException infe = expectThrows(IndexNotFoundException.class,
|
||||
() -> indexNameExpressionResolver.concreteIndices(context, new String[]{}));
|
||||
assertThat(infe.getMessage(), is("no such index [_all] and no indices exist"));
|
||||
}
|
||||
|
||||
public void testConcreteIndicesWildcardExpansion() {
|
||||
MetaData.Builder mdBuilder = MetaData.builder()
|
||||
|
|
|
@ -160,7 +160,7 @@ public class SimpleValidateQueryIT extends ESIntegTestCase {
|
|||
client().admin().indices().prepareValidateQuery().get();
|
||||
fail("Expected IndexNotFoundException");
|
||||
} catch (IndexNotFoundException e) {
|
||||
assertThat(e.getMessage(), is("no such index [null]"));
|
||||
assertThat(e.getMessage(), is("no such index [null] and no indices exist"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue