Make sure that field aliases count towards the total fields limit. (#32222)

This commit is contained in:
Julie Tibshirani 2018-07-20 10:06:07 -07:00 committed by GitHub
parent c6c9075ca4
commit af0c1d30fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -427,7 +427,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
// the master node restoring mappings from disk or data nodes
// deserializing cluster state that was sent by the master node,
// this check will be skipped.
checkTotalFieldsLimit(objectMappers.size() + fieldMappers.size());
checkTotalFieldsLimit(objectMappers.size() + fieldMappers.size() + fieldAliasMappers.size());
}
results.put(newMapper.type(), newMapper);

View File

@ -270,6 +270,37 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
assertThat(e.getMessage(), containsString("Invalid [path] value [nested.field] for field alias [alias]"));
}
public void testTotalFieldsLimitWithFieldAlias() throws Throwable {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties")
.startObject("alias")
.field("type", "alias")
.field("path", "field")
.endObject()
.startObject("field")
.field("type", "text")
.endObject()
.endObject()
.endObject().endObject());
DocumentMapper documentMapper = createIndex("test1").mapperService()
.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
// Set the total fields limit to the number of non-alias fields, to verify that adding
// a field alias pushes the mapping over the limit.
int numFields = documentMapper.mapping().metadataMappers.length + 2;
int numNonAliasFields = numFields - 1;
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
Settings settings = Settings.builder()
.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), numNonAliasFields)
.build();
createIndex("test2", settings).mapperService()
.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
});
assertEquals("Limit of total fields [" + numNonAliasFields + "] in index [test2] has been exceeded", e.getMessage());
}
public void testForbidMultipleTypes() throws IOException {
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject());
MapperService mapperService = createIndex("test").mapperService();