From c8c2bd84bb4827ce8fefdf41fb5a5fdc8636e5db Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Mon, 30 Jul 2018 18:25:06 -0700 Subject: [PATCH] Improve the error message when an index is incompatible with field aliases. --- .../elasticsearch/percolator/PercolateQueryBuilderTests.java | 2 +- .../java/org/elasticsearch/index/mapper/FieldAliasMapper.java | 3 ++- .../org/elasticsearch/index/mapper/FieldAliasMapperTests.java | 4 ++-- .../elasticsearch/index/query/TermsSetQueryBuilderTests.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolateQueryBuilderTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolateQueryBuilderTests.java index 38c014132fe58..660cbf291c801 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolateQueryBuilderTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolateQueryBuilderTests.java @@ -377,7 +377,7 @@ public void testSerializationFailsUnlessFetched() throws IOException { } public void testFieldAlias() throws IOException { - assumeTrue("Test only runs when there is a single mapping type.", isSingleType()); + assumeTrue("Test only runs on indexes that enforce a single mapping type.", isSingleType()); QueryShardContext shardContext = createShardContext(); diff --git a/server/src/main/java/org/elasticsearch/index/mapper/FieldAliasMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/FieldAliasMapper.java index 6f785f604cf52..1e5857c9087ca 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/FieldAliasMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/FieldAliasMapper.java @@ -115,7 +115,8 @@ public Mapper.Builder parse(String name, Map node, ParserContext private static void checkIndexCompatibility(IndexSettings settings, String name) { if (!settings.isSingleType()) { throw new IllegalStateException("Cannot create a field alias [" + name + "] " + - "on index [" + settings.getIndex().getName() + "], as it has multiple types."); + "for index [" + settings.getIndex().getName() + "]. Field aliases can only " + + "be specified on indexes that enforce a single mapping type."); } } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java index 12b723c713043..24494d46e004a 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldAliasMapperTests.java @@ -200,7 +200,7 @@ public void testFieldAliasDisallowedWithMultipleTypes() throws IOException { .endObject()); IllegalStateException e = expectThrows(IllegalStateException.class, () -> parser.parse("type", new CompressedXContent(mapping))); - assertEquals("Cannot create a field alias [alias-field] on index [alias-test]," - + " as it has multiple types.", e.getMessage()); + assertEquals("Cannot create a field alias [alias-field] for index [alias-test]. Field aliases" + + " can only be specified on indexes that enforce a single mapping type.", e.getMessage()); } } diff --git a/server/src/test/java/org/elasticsearch/index/query/TermsSetQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/TermsSetQueryBuilderTests.java index 51875a97ca63d..1a45c17749eb1 100644 --- a/server/src/test/java/org/elasticsearch/index/query/TermsSetQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/TermsSetQueryBuilderTests.java @@ -263,7 +263,7 @@ public void testDoToQuery_msmScriptField() throws Exception { } public void testFieldAlias() { - assumeTrue("Test runs only when there is a single mapping type.", isSingleType()); + assumeTrue("Test only runs on indexes that enforce a single mapping type.", isSingleType()); List randomTerms = Arrays.asList(generateRandomStringArray(5, 10, false, false)); TermsSetQueryBuilder queryBuilder = new TermsSetQueryBuilder(STRING_ALIAS_FIELD_NAME, randomTerms)