From 3c3c7f63a91e70fdeb6916e8eac0279f796a242e Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Sun, 21 Oct 2018 10:12:23 +0500 Subject: [PATCH 1/6] Improved IndexNotFoundException's default error message by including the missing index name. Fixes #34628. --- .../java/org/elasticsearch/index/IndexNotFoundException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java index 4442ee276c9cf..4a1f7d12b8faa 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java +++ b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java @@ -37,7 +37,7 @@ public IndexNotFoundException(String index) { } public IndexNotFoundException(String index, Throwable cause) { - super("no such index", cause); + super("no such index: [" + index + "]", cause); setIndex(index); } @@ -46,7 +46,7 @@ public IndexNotFoundException(Index index) { } public IndexNotFoundException(Index index, Throwable cause) { - super("no such index", cause); + super("no such index: " + index.toString(), cause); setIndex(index); } From 4c1a131a49c14c72bd9b4ff22027302590883716 Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Tue, 23 Oct 2018 03:56:01 +0500 Subject: [PATCH 2/6] Fixed tests --- .../java/org/elasticsearch/client/CrudIT.java | 6 ++-- .../client/GetAliasesResponseTests.java | 6 ++-- .../elasticsearch/client/IndicesClientIT.java | 18 +++++++----- .../org/elasticsearch/client/SearchIT.java | 2 +- .../documentation/CRUDDocumentationIT.java | 2 +- .../mustache/MultiSearchTemplateIT.java | 2 +- .../index/reindex/ReindexFailureTests.java | 2 +- .../index/IndexNotFoundException.java | 4 +-- .../ElasticsearchExceptionTests.java | 2 +- .../action/admin/indices/get/GetIndexIT.java | 2 +- .../bulk/BulkProcessorClusterSettingsIT.java | 2 +- .../termvectors/MultiTermVectorsIT.java | 2 +- .../cluster/SimpleClusterStateIT.java | 4 +-- .../IndexNameExpressionResolverTests.java | 6 ++-- .../MetaDataCreateIndexServiceTests.java | 8 ++--- .../allocation/AllocationCommandsTests.java | 2 +- .../flush/SyncedFlushSingleNodeTests.java | 2 +- .../indices/state/OpenCloseIndexIT.java | 8 ++--- .../org/elasticsearch/mget/SimpleMgetIT.java | 4 +-- .../validate/SimpleValidateQueryIT.java | 2 +- .../xpack/ccr/FollowIndexIT.java | 4 +-- .../xpack/ccr/IndexFollowingIT.java | 4 +-- .../RollupResponseTranslationTests.java | 4 +-- .../security/authz/IndexAliasesTests.java | 2 +- .../authz/IndicesAndAliasesResolverTests.java | 29 ++++++++++++------- .../security/authz/ReadActionsTests.java | 12 ++++---- .../xpack/security/ReindexWithSecurityIT.java | 6 ++-- 27 files changed, 79 insertions(+), 68 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java index 3f90552fe9b54..99e05fc186064 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java @@ -196,7 +196,7 @@ public void testGet() throws IOException { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); - assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index]", exception.getMessage()); + assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", exception.getMessage()); assertEquals("index", exception.getMetadata("es.index").get(0)); } IndexRequest index = new IndexRequest("index", "type", "id"); @@ -283,7 +283,7 @@ public void testMultiGet() throws IOException { assertEquals("id1", response.getResponses()[0].getFailure().getId()); assertEquals("type", response.getResponses()[0].getFailure().getType()); assertEquals("index", response.getResponses()[0].getFailure().getIndex()); - assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index]", + assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", response.getResponses()[0].getFailure().getFailure().getMessage()); assertTrue(response.getResponses()[1].isFailed()); @@ -291,7 +291,7 @@ public void testMultiGet() throws IOException { assertEquals("id2", response.getResponses()[1].getId()); assertEquals("type", response.getResponses()[1].getType()); assertEquals("index", response.getResponses()[1].getIndex()); - assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index]", + assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]", response.getResponses()[1].getFailure().getFailure().getMessage()); } BulkRequest bulk = new BulkRequest(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/GetAliasesResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/GetAliasesResponseTests.java index c5bc74e7517c3..92210521b3d0c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/GetAliasesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/GetAliasesResponseTests.java @@ -109,7 +109,7 @@ public void testFromXContentWithElasticsearchException() throws IOException { " \"root_cause\": [" + " {" + " \"type\": \"index_not_found_exception\"," + - " \"reason\": \"no such index\"," + + " \"reason\": \"no such index [index]\"," + " \"resource.type\": \"index_or_alias\"," + " \"resource.id\": \"index\"," + " \"index_uuid\": \"_na_\"," + @@ -117,7 +117,7 @@ public void testFromXContentWithElasticsearchException() throws IOException { " }" + " ]," + " \"type\": \"index_not_found_exception\"," + - " \"reason\": \"no such index\"," + + " \"reason\": \"no such index [index]\"," + " \"resource.type\": \"index_or_alias\"," + " \"resource.id\": \"index\"," + " \"index_uuid\": \"_na_\"," + @@ -131,7 +131,7 @@ public void testFromXContentWithElasticsearchException() throws IOException { assertThat(getAliasesResponse.getError(), nullValue()); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getException().getMessage(), - equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]")); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 533f6bcb22e25..832aba51e2b41 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -573,7 +573,8 @@ public void testAliasesNonExistentIndex() throws IOException { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(nonExistentIndexRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync)); assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); - assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + assertThat(exception.getMessage(), + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); assertThat(exception.getMetadata("es.index"), hasItem(nonExistentIndex)); createIndex(index, Settings.EMPTY); @@ -583,7 +584,8 @@ public void testAliasesNonExistentIndex() throws IOException { exception = expectThrows(ElasticsearchStatusException.class, () -> execute(mixedRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync)); assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); - assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + assertThat(exception.getMessage(), + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); assertThat(exception.getMetadata("es.index"), hasItem(nonExistentIndex)); assertThat(exception.getMetadata("es.index"), not(hasItem(index))); assertThat(aliasExists(index, alias), equalTo(false)); @@ -595,7 +597,8 @@ public void testAliasesNonExistentIndex() throws IOException { exception = expectThrows(ElasticsearchException.class, () -> execute(removeIndexRequest, highLevelClient().indices()::updateAliases, highLevelClient().indices()::updateAliasesAsync)); assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); - assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + assertThat(exception.getMessage(), + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); assertThat(exception.getMetadata("es.index"), hasItem(nonExistentIndex)); assertThat(exception.getMetadata("es.index"), not(hasItem(index))); assertThat(aliasExists(index, alias), equalTo(false)); @@ -1060,7 +1063,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException { highLevelClient().indices()::getAliasAsync); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getException().getMessage(), - equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]")); } { GetAliasesRequest getAliasesRequest = new GetAliasesRequest(alias); @@ -1077,7 +1080,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException { highLevelClient().indices()::getAliasAsync); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getException().getMessage(), - equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); } { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index").aliases(alias); @@ -1085,7 +1088,7 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException { highLevelClient().indices()::getAliasAsync); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getException().getMessage(), - equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); } { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices("non_existent_index*"); @@ -1199,7 +1202,8 @@ public void testIndexPutSettingNonExistent() throws IOException { ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); - assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + assertThat(exception.getMessage(), + equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]")); createIndex(index, Settings.EMPTY); exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest, diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java index 063fce9bcac5e..f6aa97def28e4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java @@ -1079,7 +1079,7 @@ public void testExplainNonExistent() throws IOException { assertThat(exception.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(exception.getIndex().getName(), equalTo("non_existent_index")); assertThat(exception.getDetailedMessage(), - containsString("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); + containsString("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); } { ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "999"); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java index 4e3f778cd151b..e4eba7e11e44b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java @@ -1592,7 +1592,7 @@ public void testMultiGet() throws Exception { // TODO status is broken! fix in a followup // assertEquals(RestStatus.NOT_FOUND, ee.status()); // <4> assertThat(e.getMessage(), - containsString("reason=no such index")); // <5> + containsString("reason=no such index [missing_index]")); // <5> // end::multi-get-indexnotfound // tag::multi-get-execute-listener diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java index c3ec5ae1784a9..0463069609d4c 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java @@ -169,7 +169,7 @@ public void testBasic() throws Exception { MultiSearchTemplateResponse.Item response4 = response.getResponses()[3]; assertThat(response4.isFailure(), is(true)); assertThat(response4.getFailure(), instanceOf(IndexNotFoundException.class)); - assertThat(response4.getFailure().getMessage(), equalTo("no such index")); + assertThat(response4.getFailure().getMessage(), equalTo("no such index [unknown]")); MultiSearchTemplateResponse.Item response5 = response.getResponses()[4]; assertThat(response5.isFailure(), is(false)); diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java index f5e234f66ca57..87c7c07007eb7 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexFailureTests.java @@ -120,7 +120,7 @@ public void testResponseOnSearchFailure() throws Exception { assertThat(e.getMessage(), either(containsString("all shards failed")) .or(containsString("No search context found")) - .or(containsString("no such index")) + .or(containsString("no such index [source]")) ); return; } diff --git a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java index 4a1f7d12b8faa..ba20991c72521 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java +++ b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java @@ -37,7 +37,7 @@ public IndexNotFoundException(String index) { } public IndexNotFoundException(String index, Throwable cause) { - super("no such index: [" + index + "]", cause); + super("no such index [" + index + "]", cause); setIndex(index); } @@ -46,7 +46,7 @@ public IndexNotFoundException(Index index) { } public IndexNotFoundException(Index index, Throwable cause) { - super("no such index: " + index.toString(), cause); + super("no such index " + index.toString(), cause); setIndex(index); } diff --git a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 6e4c97fd3dad2..c014845ce093d 100644 --- a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -114,7 +114,7 @@ public void testGuessRootCause() { ElasticsearchException[] rootCauses = exception.guessRootCauses(); assertEquals(rootCauses.length, 1); assertEquals(ElasticsearchException.getExceptionName(rootCauses[0]), "index_not_found_exception"); - assertEquals(rootCauses[0].getMessage(), "no such index"); + assertEquals("no such index [foo]", rootCauses[0].getMessage()); ShardSearchFailure failure = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 1, null)); ShardSearchFailure failure1 = new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index ba4aa3015f308..48914fca13133 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -73,7 +73,7 @@ public void testSimpleUnknownIndex() { client().admin().indices().prepareGetIndex().addIndices("missing_idx").get(); fail("Expected IndexNotFoundException"); } catch (IndexNotFoundException e) { - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [missing_idx]")); } } diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java index ca1630b00641c..e82be77fc147c 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java @@ -45,7 +45,7 @@ public void testBulkProcessorAutoCreateRestrictions() throws Exception { assertEquals(3, responses.length); assertFalse("Operation on existing index should succeed", responses[0].isFailed()); assertTrue("Missing index should have been flagged", responses[1].isFailed()); - assertEquals("[wontwork] IndexNotFoundException[no such index]", responses[1].getFailureMessage()); + assertEquals("[wontwork] IndexNotFoundException[no such index [wontwork]]", responses[1].getFailureMessage()); assertFalse("Operation on existing index should succeed", responses[2].isFailed()); } } diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java index 10a4c9f3e1d7a..2f75f6df1a88e 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsIT.java @@ -76,7 +76,7 @@ public void testMissingIndexThrowsMissingIndex() throws Exception { MultiTermVectorsResponse response = mtvBuilder.execute().actionGet(); assertThat(response.getResponses().length, equalTo(1)); assertThat(response.getResponses()[0].getFailure().getCause(), instanceOf(IndexNotFoundException.class)); - assertThat(response.getResponses()[0].getFailure().getCause().getMessage(), equalTo("no such index")); + assertThat(response.getResponses()[0].getFailure().getCause().getMessage(), equalTo("no such index [testX]")); } public void testMultiTermVectorsWithVersion() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 606e716d210b2..3e27b784e0a10 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -271,7 +271,7 @@ public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception { client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*").setIndicesOptions(allowNoIndices).get(); fail("Expected IndexNotFoundException"); } catch (IndexNotFoundException e) { - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [a*]")); } } @@ -282,7 +282,7 @@ public void testIndicesIgnoreUnavailableFalse() throws Exception { client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("fzzbzz").setIndicesOptions(allowNoIndices).get(); fail("Expected IndexNotFoundException"); } catch (IndexNotFoundException e) { - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [fzzbzz]")); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java index 9ad9603b1489b..0832df7c896d9 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -530,7 +530,7 @@ public void testConcreteIndicesIgnoreIndicesOneMissingIndex() { IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testZZZ")); - assertThat(infe.getMessage(), is("no such index")); + assertThat(infe.getMessage(), is("no such index [testZZZ]")); } public void testConcreteIndicesIgnoreIndicesOneMissingIndexOtherFound() { @@ -552,7 +552,7 @@ public void testConcreteIndicesIgnoreIndicesAllMissing() { IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy")); - assertThat(infe.getMessage(), is("no such index")); + assertThat(infe.getMessage(), is("no such index [testMo]")); } public void testConcreteIndicesIgnoreIndicesEmptyRequest() { @@ -1161,7 +1161,7 @@ public void testDeleteIndexIgnoresAliases() { IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(state, new DeleteIndexRequest("does_not_exist"))); assertEquals("does_not_exist", infe.getIndex().getName()); - assertEquals("no such index", infe.getMessage()); + assertEquals("no such index [does_not_exist]", infe.getMessage()); } { IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java index efef803be8418..5ccacee395a31 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java @@ -124,9 +124,9 @@ public void testValidateShrinkIndex() { MetaDataCreateIndexService.validateShrinkIndex(state, "target", Collections.emptySet(), "source", Settings.EMPTY) ).getMessage()); - assertEquals("no such index", + assertEquals("no such index [no_such_index]", expectThrows(IndexNotFoundException.class, () -> - MetaDataCreateIndexService.validateShrinkIndex(state, "no such index", Collections.emptySet(), "target", Settings.EMPTY) + MetaDataCreateIndexService.validateShrinkIndex(state, "no_such_index", Collections.emptySet(), "target", Settings.EMPTY) ).getMessage()); Settings targetSettings = Settings.builder().put("index.number_of_shards", 1).build(); @@ -200,9 +200,9 @@ public void testValidateSplitIndex() { MetaDataCreateIndexService.validateSplitIndex(state, "target", Collections.emptySet(), "source", targetSettings) ).getMessage()); - assertEquals("no such index", + assertEquals("no such index [no_such_index]", expectThrows(IndexNotFoundException.class, () -> - MetaDataCreateIndexService.validateSplitIndex(state, "no such index", Collections.emptySet(), "target", targetSettings) + MetaDataCreateIndexService.validateSplitIndex(state, "no_such_index", Collections.emptySet(), "target", targetSettings) ).getMessage()); assertEquals("the number of source shards [10] must be less that the number of target shards [5]", diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index da0920e69373b..1a50ac03e4c4b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -180,7 +180,7 @@ public void testAllocateCommand() { allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand("test2", 0, "node2")), false, false); fail("expected ShardNotFoundException when allocating non-existing index"); } catch (IndexNotFoundException e) { - assertThat(e.getMessage(), containsString("no such index")); + assertThat(e.getMessage(), containsString("no such index [test2]")); } logger.info("--> allocating empty primary with acceptDataLoss flag set to false"); diff --git a/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java b/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java index 3bfcfdd3ab187..83411ad2bc208 100644 --- a/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java +++ b/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java @@ -156,7 +156,7 @@ public void testSyncFailsOnIndexClosedOrMissing() throws InterruptedException { listener.latch.await(); assertNotNull(listener.error); assertNull(listener.result); - assertEquals("no such index", listener.error.getMessage()); + assertEquals("no such index [index not found]", listener.error.getMessage()); } public void testFailAfterIntermediateCommit() throws InterruptedException { diff --git a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java index 96bb9ab8a1ce7..f37dde7ec09a6 100644 --- a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java @@ -76,14 +76,14 @@ public void testSimpleCloseMissingIndex() { Client client = client(); Exception e = expectThrows(IndexNotFoundException.class, () -> client.admin().indices().prepareClose("test1").execute().actionGet()); - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [test1]")); } public void testSimpleOpenMissingIndex() { Client client = client(); Exception e = expectThrows(IndexNotFoundException.class, () -> client.admin().indices().prepareOpen("test1").execute().actionGet()); - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [test1]")); } public void testCloseOneMissingIndex() { @@ -93,7 +93,7 @@ public void testCloseOneMissingIndex() { assertThat(healthResponse.isTimedOut(), equalTo(false)); Exception e = expectThrows(IndexNotFoundException.class, () -> client.admin().indices().prepareClose("test1", "test2").execute().actionGet()); - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [test2]")); } public void testCloseOneMissingIndexIgnoreMissing() { @@ -114,7 +114,7 @@ public void testOpenOneMissingIndex() { assertThat(healthResponse.isTimedOut(), equalTo(false)); Exception e = expectThrows(IndexNotFoundException.class, () -> client.admin().indices().prepareOpen("test1", "test2").execute().actionGet()); - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [test2]")); } public void testOpenOneMissingIndexIgnoreMissing() { diff --git a/server/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java b/server/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java index 670f9cdfa08be..c7f27dc81a7c4 100644 --- a/server/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java +++ b/server/src/test/java/org/elasticsearch/mget/SimpleMgetIT.java @@ -62,7 +62,7 @@ public void testThatMgetShouldWorkWithOneIndexMissing() throws IOException { assertThat(mgetResponse.getResponses()[1].getIndex(), is("nonExistingIndex")); assertThat(mgetResponse.getResponses()[1].isFailed(), is(true)); - assertThat(mgetResponse.getResponses()[1].getFailure().getMessage(), is("no such index")); + assertThat(mgetResponse.getResponses()[1].getFailure().getMessage(), is("no such index [nonExistingIndex]")); assertThat(((ElasticsearchException) mgetResponse.getResponses()[1].getFailure().getFailure()).getIndex().getName(), is("nonExistingIndex")); @@ -72,7 +72,7 @@ public void testThatMgetShouldWorkWithOneIndexMissing() throws IOException { assertThat(mgetResponse.getResponses().length, is(1)); assertThat(mgetResponse.getResponses()[0].getIndex(), is("nonExistingIndex")); assertThat(mgetResponse.getResponses()[0].isFailed(), is(true)); - assertThat(mgetResponse.getResponses()[0].getFailure().getMessage(), is("no such index")); + assertThat(mgetResponse.getResponses()[0].getFailure().getMessage(), is("no such index [nonExistingIndex]")); assertThat(((ElasticsearchException) mgetResponse.getResponses()[0].getFailure().getFailure()).getIndex().getName(), is("nonExistingIndex")); } diff --git a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java index 9ef47af29cd94..2ef817e98ba75 100644 --- a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java +++ b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java @@ -151,7 +151,7 @@ public void testValidateEmptyCluster() { client().admin().indices().prepareValidateQuery().get(); fail("Expected IndexNotFoundException"); } catch (IndexNotFoundException e) { - assertThat(e.getMessage(), is("no such index")); + assertThat(e.getMessage(), is("no such index [null]")); } } diff --git a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java index 9383d653de6d8..d2676cf6fa8f0 100644 --- a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java +++ b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java @@ -71,11 +71,11 @@ public void testFollowIndex() throws Exception { public void testFollowNonExistingLeaderIndex() throws Exception { assumeFalse("Test should only run when both clusters are running", "leader".equals(targetCluster)); ResponseException e = expectThrows(ResponseException.class, () -> resumeFollow("non-existing-index")); - assertThat(e.getMessage(), containsString("no such index")); + assertThat(e.getMessage(), containsString("no such index [non-existing-index]")); assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404)); e = expectThrows(ResponseException.class, () -> followIndex("non-existing-index", "non-existing-index")); - assertThat(e.getMessage(), containsString("no such index")); + assertThat(e.getMessage(), containsString("no such index [non-existing-index]")); assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404)); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 5d7d58eb9b324..0b69a3f8a004b 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -522,7 +522,7 @@ public void testDeleteLeaderIndex() throws Exception { assertThat(response.getStatsResponses().get(0).status().numberOfFailedFetches(), greaterThanOrEqualTo(1L)); ElasticsearchException fatalException = response.getStatsResponses().get(0).status().getFatalException(); assertThat(fatalException, notNullValue()); - assertThat(fatalException.getRootCause().getMessage(), equalTo("no such index")); + assertThat(fatalException.getRootCause().getMessage(), equalTo("no such index [index1]")); }); pauseFollow("index2"); ensureNoCcrTasks(); @@ -552,7 +552,7 @@ public void testDeleteFollowerIndex() throws Exception { assertThat(response.getStatsResponses().get(0).status().numberOfFailedBulkOperations(), greaterThanOrEqualTo(1L)); ElasticsearchException fatalException = response.getStatsResponses().get(0).status().getFatalException(); assertThat(fatalException, notNullValue()); - assertThat(fatalException.getMessage(), equalTo("no such index")); + assertThat(fatalException.getMessage(), equalTo("no such index [index2]")); }); pauseFollow("index2"); ensureNoCcrTasks(); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java index 576f37d78440e..849461f1b6202 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java @@ -231,7 +231,7 @@ public void testVerifyMissingNormal() { MultiSearchResponse.Item missing = new MultiSearchResponse.Item(null, new IndexNotFoundException("foo")); Exception e = expectThrows(RuntimeException.class, () -> RollupResponseTranslator.verifyResponse(missing)); - assertThat(e.getMessage(), equalTo("no such index")); + assertThat(e.getMessage(), equalTo("no such index [foo]")); } public void testTranslateRollup() { @@ -287,7 +287,7 @@ public void testTranslateMissingRollup() { Exception e = expectThrows(RuntimeException.class, () -> RollupResponseTranslator.translateResponse(new MultiSearchResponse.Item[]{missing}, context)); - assertThat(e.getMessage(), equalTo("no such index")); + assertThat(e.getMessage(), equalTo("no such index [foo]")); } public void testMissingFilter() { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndexAliasesTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndexAliasesTests.java index dca113b6e4229..711ca517d98c3 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndexAliasesTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndexAliasesTests.java @@ -509,7 +509,7 @@ public void testGetAliasesAliasesOnlyPermissionStrict() { //security plugin lets it through, but es core intercepts it due to strict indices options and throws index not found IndexNotFoundException indexNotFoundException = expectThrows(IndexNotFoundException.class, client.admin().indices() .prepareGetAliases("alias_1").addIndices("test_1").setIndicesOptions(IndicesOptions.strictExpandOpen())::get); - assertEquals("no such index", indexNotFoundException.getMessage()); + assertEquals("no such index [test_1]", indexNotFoundException.getMessage()); //fails: no manage_aliases privilege on non_authorized alias assertThrowsAuthorizationException(client.admin().indices().prepareGetAliases("non_authorized").addIndices("test_1") diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java index 4dc0909552c26..f70d69ad72e69 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java @@ -68,6 +68,9 @@ import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; import org.elasticsearch.xpack.security.support.SecurityIndexManager; import org.elasticsearch.xpack.security.test.SecurityTestUtils; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; import org.junit.Before; import java.util.Arrays; @@ -469,7 +472,7 @@ public void testResolveNonMatchingIndicesDisallowNoIndices() { request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, SearchAction.NAME))); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [missing*]", e.getMessage()); } public void testResolveExplicitIndicesStrict() { @@ -506,7 +509,7 @@ public void testResolveNoAuthorizedIndicesDisallowNoIndices() { request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(userNoIndices, SearchAction.NAME))); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [[]]", e.getMessage()); } public void testResolveMissingIndexStrict() { @@ -848,7 +851,7 @@ public void testGetAliasesRequestMissingIndexIgnoreUnavailableDisallowNoIndices( request.aliases("alias2"); IndexNotFoundException exception = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, GetAliasesAction.NAME)).getLocal()); - assertEquals("no such index", exception.getMessage()); + assertEquals("no such index [[missing]]", exception.getMessage()); } public void testGetAliasesRequestMissingIndexIgnoreUnavailableAllowNoIndices() { @@ -928,7 +931,7 @@ public void testWildcardsGetAliasesRequestNoMatchingIndicesDisallowNoIndices() { request.indices("non_matching_*"); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, GetAliasesAction.NAME)).getLocal()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [non_matching_*]", e.getMessage()); } public void testWildcardsGetAliasesRequestNoMatchingIndicesAllowNoIndices() { @@ -995,7 +998,7 @@ public void testAllGetAliasesRequestNoAuthorizedIndicesDisallowNoIndices() { request.indices("_all"); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(userNoIndices, GetAliasesAction.NAME))); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [[_all]]", e.getMessage()); } public void testWildcardsGetAliasesRequestNoAuthorizedIndicesAllowNoIndices() { @@ -1015,7 +1018,7 @@ public void testWildcardsGetAliasesRequestNoAuthorizedIndicesDisallowNoIndices() //current user is not authorized for any index, foo* resolves to no indices, the request fails IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(userNoIndices, GetAliasesAction.NAME))); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [foo*]", e.getMessage()); } public void testResolveAllAliasesGetAliasesRequest() { @@ -1149,7 +1152,7 @@ public void testNonRemotableRequestDoesNotAllowRemoteIndices() { ); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(tuple.v1(), buildAuthorizedIndices(user, tuple.v2())).getLocal()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [[remote:foo]]", e.getMessage()); } public void testNonRemotableRequestDoesNotAllowRemoteWildcardIndices() { @@ -1267,15 +1270,17 @@ public void testUnauthorizedDateMathExpressionIgnoreUnavailableDisallowNoIndices request.indicesOptions(IndicesOptions.fromOptions(true, false, randomBoolean(), randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, SearchAction.NAME))); - assertEquals("no such index" , e.getMessage()); + assertEquals("no such index [[]]" , e.getMessage()); } public void testUnauthorizedDateMathExpressionStrict() { + String expectedIndex = "datetime-" + DateTimeFormat.forPattern("YYYY.MM.dd").print( + new DateTime(DateTimeZone.UTC).monthOfYear().roundFloorCopy()); SearchRequest request = new SearchRequest(""); request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, SearchAction.NAME))); - assertEquals("no such index" , e.getMessage()); + assertEquals("no such index [" + expectedIndex + "]" , e.getMessage()); } public void testResolveDateMathExpression() { @@ -1307,15 +1312,17 @@ public void testMissingDateMathExpressionIgnoreUnavailableDisallowNoIndices() { request.indicesOptions(IndicesOptions.fromOptions(true, false, randomBoolean(), randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, SearchAction.NAME))); - assertEquals("no such index" , e.getMessage()); + assertEquals("no such index [[]]" , e.getMessage()); } public void testMissingDateMathExpressionStrict() { + String expectedIndex = "foobar-" + DateTimeFormat.forPattern("YYYY.MM.dd").print( + new DateTime(DateTimeZone.UTC).monthOfYear().roundFloorCopy()); SearchRequest request = new SearchRequest(""); request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean())); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> resolveIndices(request, buildAuthorizedIndices(user, SearchAction.NAME))); - assertEquals("no such index" , e.getMessage()); + assertEquals("no such index [" + expectedIndex + "]" , e.getMessage()); } public void testAliasDateMathExpressionNotSupported() { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java index 76568d3d48b5a..e9ed559ab8e47 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java @@ -73,7 +73,7 @@ public void testSearchNonAuthorizedWildcardDisallowNoIndices() { createIndicesWithRandomAliases("test1", "test2", "index1", "index2"); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("index*") .setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [index*]", e.getMessage()); } public void testEmptyClusterSearchForAll() { @@ -83,7 +83,7 @@ public void testEmptyClusterSearchForAll() { public void testEmptyClusterSearchForAllDisallowNoIndices() { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch() .setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [[]]", e.getMessage()); } public void testEmptyClusterSearchForWildcard() { @@ -94,7 +94,7 @@ public void testEmptyClusterSearchForWildcard() { public void testEmptyClusterSearchForWildcardDisallowNoIndices() { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("*") .setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [*]", e.getMessage()); } public void testEmptyAuthorizedIndicesSearchForAll() { @@ -106,7 +106,7 @@ public void testEmptyAuthorizedIndicesSearchForAllDisallowNoIndices() { createIndicesWithRandomAliases("index1", "index2"); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch() .setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [[]]", e.getMessage()); } public void testEmptyAuthorizedIndicesSearchForWildcard() { @@ -118,7 +118,7 @@ public void testEmptyAuthorizedIndicesSearchForWildcardDisallowNoIndices() { createIndicesWithRandomAliases("index1", "index2"); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("*") .setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [*]", e.getMessage()); } public void testExplicitNonAuthorizedIndex() { @@ -277,7 +277,7 @@ public void testMultiSearchMissingAuthorizedIndex() { assertReturnedIndices(multiSearchResponse.getResponses()[0].getResponse(), "test1", "test2", "test3"); assertTrue(multiSearchResponse.getResponses()[1].isFailure()); assertThat(multiSearchResponse.getResponses()[1].getFailure().toString(), - equalTo("[test4] IndexNotFoundException[no such index]")); + equalTo("[test4] IndexNotFoundException[no such index [test4]]")); } { //we set ignore_unavailable and allow_no_indices to true, no errors returned, second item doesn't have hits. diff --git a/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java b/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java index 48e1a46c3ab57..0a75565fbc075 100644 --- a/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java +++ b/x-pack/qa/reindex-tests-with-security/src/test/java/org/elasticsearch/xpack/security/ReindexWithSecurityIT.java @@ -60,7 +60,7 @@ public void testDeleteByQuery() { .source("test1", "index1") .filter(QueryBuilders.matchAllQuery()) .get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [index1]", e.getMessage()); } public void testUpdateByQuery() { @@ -75,7 +75,7 @@ public void testUpdateByQuery() { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> new UpdateByQueryRequestBuilder(client(), UpdateByQueryAction.INSTANCE).source("test1", "index1").get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [index1]", e.getMessage()); } public void testReindex() { @@ -90,6 +90,6 @@ public void testReindex() { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> new ReindexRequestBuilder(client(), ReindexAction.INSTANCE).source("test1", "index1").destination("dest").get()); - assertEquals("no such index", e.getMessage()); + assertEquals("no such index [index1]", e.getMessage()); } } From edf63016a54d0680f75c891a769c1aedcfe6a786 Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Tue, 23 Oct 2018 14:23:40 +0500 Subject: [PATCH 3/6] More consistent index name in the error message --- .../java/org/elasticsearch/index/IndexNotFoundException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java index ba20991c72521..923781c6be68f 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java +++ b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java @@ -46,7 +46,7 @@ public IndexNotFoundException(Index index) { } public IndexNotFoundException(Index index, Throwable cause) { - super("no such index " + index.toString(), cause); + super("no such index [" + index.getName() + "]", cause); setIndex(index); } From 3ab8f53bf09475155000354864a1411729e56e7f Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Tue, 23 Oct 2018 18:23:59 +0500 Subject: [PATCH 4/6] Improved custom message ctor and fixed its usages. --- .../action/support/AutoCreateIndex.java | 8 ++++---- .../elasticsearch/index/IndexNotFoundException.java | 2 +- .../action/support/AutoCreateIndexTests.java | 12 +++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java b/server/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java index d834d80338432..f530a81e51daa 100644 --- a/server/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java +++ b/server/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java @@ -73,10 +73,10 @@ public boolean shouldAutoCreate(String index, ClusterState state) { // One volatile read, so that all checks are done against the same instance: final AutoCreate autoCreate = this.autoCreate; if (autoCreate.autoCreateIndex == false) { - throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] is [false]", index); + throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] is [false]", index); } if (dynamicMappingDisabled) { - throw new IndexNotFoundException("no such index and [" + MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey() + "] is [false]", + throw new IndexNotFoundException("[" + MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey() + "] is [false]", index); } // matches not set, default value of "true" @@ -90,11 +90,11 @@ public boolean shouldAutoCreate(String index, ClusterState state) { if (include) { return true; } - throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-" + throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-" + indexExpression + "] which forbids automatic creation of the index", index); } } - throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate + throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate + "]) doesn't match", index); } diff --git a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java index 923781c6be68f..2a4a89e3f9005 100644 --- a/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java +++ b/server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java @@ -28,7 +28,7 @@ public final class IndexNotFoundException extends ResourceNotFoundException { * Construct with a custom message. */ public IndexNotFoundException(String message, String index) { - super(message); + super("no such index [" + index + "] and " + message); setIndex(index); } diff --git a/server/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java b/server/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java index 84dfe5ec93e9f..4918939c90b86 100644 --- a/server/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java @@ -83,9 +83,10 @@ public void testHandleSpaces() { // see #21449 public void testAutoCreationDisabled() { Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false).build(); AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings); + String randomIndex = randomAlphaOfLengthBetween(1, 10); IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> - autoCreateIndex.shouldAutoCreate(randomAlphaOfLengthBetween(1, 10), buildClusterState())); - assertEquals("no such index and [action.auto_create_index] is [false]", e.getMessage()); + autoCreateIndex.shouldAutoCreate(randomIndex, buildClusterState())); + assertEquals("no such index [" + randomIndex + "] and [action.auto_create_index] is [false]", e.getMessage()); } public void testAutoCreationEnabled() { @@ -207,14 +208,15 @@ private AutoCreateIndex newAutoCreateIndex(Settings settings) { private void expectNotMatch(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index) { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(index, clusterState)); - assertEquals("no such index and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match", - e.getMessage()); + assertEquals( + "no such index [" + index + "] and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match", + e.getMessage()); } private void expectForbidden(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index, String forbiddingPattern) { IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(index, clusterState)); - assertEquals("no such index and [action.auto_create_index] contains [" + forbiddingPattern + assertEquals("no such index [" + index + "] and [action.auto_create_index] contains [" + forbiddingPattern + "] which forbids automatic creation of the index", e.getMessage()); } } From 796dec98974effdb7920e8bda5f87af16976c78d Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Wed, 24 Oct 2018 14:30:41 +0500 Subject: [PATCH 5/6] Fixed yaml test case. --- .../rest-api-spec/test/reindex/25_no_auto_create.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml index 874174fda4c93..8c282a933eca1 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml @@ -19,7 +19,7 @@ teardown: transient: action.auto_create_index: false - do: - catch: /no such index and \[action.auto_create_index\] is \[false\]/ + catch: /no such index \[test\] and \[action.auto_create_index\] is \[false\]/ reindex: body: source: @@ -41,7 +41,7 @@ teardown: id: 1 body: { "text": "test" } - do: - catch: /no such index and \[action.auto_create_index\] \(\[test\]\) doesn't match/ + catch: /no such index \[test\] and \[action.auto_create_index\] \(\[test\]\) doesn't match/ reindex: body: source: @@ -63,7 +63,7 @@ teardown: id: 1 body: { "text": "test" } - do: - catch: /no such index and \[action.auto_create_index\] contains \[-dest\] which forbids automatic creation of the index/ + catch: /no such index \[dest\] and \[action.auto_create_index\] contains \[-dest\] which forbids automatic creation of the index/ reindex: body: source: From 7a1e8826d63ebc350be4275245db5d8936b8becf Mon Sep 17 00:00:00 2001 From: Andrey Atapin Date: Wed, 24 Oct 2018 15:41:38 +0500 Subject: [PATCH 6/6] Fixed yaml test case. --- .../rest-api-spec/test/reindex/25_no_auto_create.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml index 8c282a933eca1..961084a5c04cb 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/25_no_auto_create.yml @@ -19,7 +19,7 @@ teardown: transient: action.auto_create_index: false - do: - catch: /no such index \[test\] and \[action.auto_create_index\] is \[false\]/ + catch: /no such index \[dest\] and \[action.auto_create_index\] is \[false\]/ reindex: body: source: @@ -41,7 +41,7 @@ teardown: id: 1 body: { "text": "test" } - do: - catch: /no such index \[test\] and \[action.auto_create_index\] \(\[test\]\) doesn't match/ + catch: /no such index \[dest\] and \[action.auto_create_index\] \(\[test\]\) doesn't match/ reindex: body: source: