Skip to content

Commit d65c8d1

Browse files
committed
Ensure that field aliases cannot be used in multi-fields. (#32219)
1 parent 7501b2c commit d65c8d1

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

docs/reference/mapping/types/alias.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ field alias to query over multiple target fields in a single clause.
7474
==== Unsupported APIs
7575

7676
Writes to field aliases are not supported: attempting to use an alias in an index or update request
77-
will result in a failure. Likewise, aliases cannot be used as the target of `copy_to`.
77+
will result in a failure. Likewise, aliases cannot be used as the target of `copy_to` or in multi-fields.
7878

7979
Because alias names are not present in the document source, aliases cannot be used when performing
8080
source filtering. For example, the following request will return an empty result for `_source`:

server/src/main/java/org/elasticsearch/index/mapper/TypeParsers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ public static boolean parseMultiField(FieldMapper.Builder builder, String name,
319319
} else {
320320
throw new MapperParsingException("no type specified for property [" + multiFieldName + "]");
321321
}
322-
if (type.equals(ObjectMapper.CONTENT_TYPE) || type.equals(ObjectMapper.NESTED_CONTENT_TYPE)) {
322+
if (type.equals(ObjectMapper.CONTENT_TYPE)
323+
|| type.equals(ObjectMapper.NESTED_CONTENT_TYPE)
324+
|| type.equals(FieldAliasMapper.CONTENT_TYPE)) {
323325
throw new MapperParsingException("Type [" + type + "] cannot be used in multi field");
324326
}
325327

server/src/test/java/org/elasticsearch/index/mapper/DocumentMapperParserTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,28 @@ public void testFieldNameWithDotsConflict() throws Exception {
7676
mapperParser.parse("type", new CompressedXContent(mapping)));
7777
assertTrue(e.getMessage(), e.getMessage().contains("mapper [foo] of different type"));
7878
}
79+
80+
public void testMultiFieldsWithFieldAlias() throws Exception {
81+
IndexService indexService = createIndex("test");
82+
DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
83+
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
84+
.startObject("properties")
85+
.startObject("field")
86+
.field("type", "text")
87+
.startObject("fields")
88+
.startObject("alias")
89+
.field("type", "alias")
90+
.field("path", "other-field")
91+
.endObject()
92+
.endObject()
93+
.endObject()
94+
.startObject("other-field")
95+
.field("type", "keyword")
96+
.endObject()
97+
.endObject()
98+
.endObject().endObject());
99+
MapperParsingException e = expectThrows(MapperParsingException.class, () ->
100+
mapperParser.parse("type", new CompressedXContent(mapping)));
101+
assertEquals("Type [alias] cannot be used in multi field", e.getMessage());
102+
}
79103
}

0 commit comments

Comments
 (0)