Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that field aliases cannot be used in multi-fields. #32219

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/mapping/types/alias.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ field alias to query over multiple target fields in a single clause.
==== Unsupported APIs

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

Because alias names are not present in the document source, aliases cannot be used when performing
source filtering. For example, the following request will return an empty result for `_source`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ public static boolean parseMultiField(FieldMapper.Builder builder, String name,
} else {
throw new MapperParsingException("no type specified for property [" + multiFieldName + "]");
}
if (type.equals(ObjectMapper.CONTENT_TYPE) || type.equals(ObjectMapper.NESTED_CONTENT_TYPE)) {
if (type.equals(ObjectMapper.CONTENT_TYPE)
|| type.equals(ObjectMapper.NESTED_CONTENT_TYPE)
|| type.equals(FieldAliasMapper.CONTENT_TYPE)) {
throw new MapperParsingException("Type [" + type + "] cannot be used in multi field");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,28 @@ public void testFieldNameWithDotsConflict() throws Exception {
mapperParser.parse("type", new CompressedXContent(mapping)));
assertTrue(e.getMessage(), e.getMessage().contains("mapper [foo] of different type"));
}

public void testMultiFieldsWithFieldAlias() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser();
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
.startObject("field")
.field("type", "text")
.startObject("fields")
.startObject("alias")
.field("type", "alias")
.field("path", "other-field")
.endObject()
.endObject()
.endObject()
.startObject("other-field")
.field("type", "keyword")
.endObject()
.endObject()
.endObject().endObject());
MapperParsingException e = expectThrows(MapperParsingException.class, () ->
mapperParser.parse("type", new CompressedXContent(mapping)));
assertEquals("Type [alias] cannot be used in multi field", e.getMessage());
}
}