|
@@ -86,6 +86,8 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|
|
Setting.longSetting("index.mapping.nested_fields.limit", 50L, 0, Property.Dynamic, Property.IndexScope);
|
|
|
public static final Setting<Long> INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING =
|
|
|
Setting.longSetting("index.mapping.total_fields.limit", 1000L, 0, Property.Dynamic, Property.IndexScope);
|
|
|
+ public static final Setting<Long> INDEX_MAPPING_DEPTH_LIMIT_SETTING =
|
|
|
+ Setting.longSetting("index.mapping.depth.limit", 20L, 1, Property.Dynamic, Property.IndexScope);
|
|
|
public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true;
|
|
|
public static final Setting<Boolean> INDEX_MAPPER_DYNAMIC_SETTING =
|
|
|
Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.IndexScope);
|
|
@@ -292,6 +294,7 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|
|
// this check will be skipped.
|
|
|
checkNestedFieldsLimit(fullPathObjectMappers);
|
|
|
checkTotalFieldsLimit(objectMappers.size() + fieldMappers.size());
|
|
|
+ checkDepthLimit(fullPathObjectMappers.keySet());
|
|
|
}
|
|
|
|
|
|
Set<String> parentTypes = this.parentTypes;
|
|
@@ -418,6 +421,27 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void checkDepthLimit(Collection<String> objectPaths) {
|
|
|
+ final long maxDepth = indexSettings.getValue(INDEX_MAPPING_DEPTH_LIMIT_SETTING);
|
|
|
+ for (String objectPath : objectPaths) {
|
|
|
+ checkDepthLimit(objectPath, maxDepth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkDepthLimit(String objectPath, long maxDepth) {
|
|
|
+ int numDots = 0;
|
|
|
+ for (int i = 0; i < objectPath.length(); ++i) {
|
|
|
+ if (objectPath.charAt(i) == '.') {
|
|
|
+ numDots += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ final int depth = numDots + 2;
|
|
|
+ if (depth > maxDepth) {
|
|
|
+ throw new IllegalArgumentException("Limit of mapping depth [" + maxDepth + "] in index [" + index().getName()
|
|
|
+ + "] has been exceeded due to object field [" + objectPath + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public DocumentMapper parse(String mappingType, CompressedXContent mappingSource, boolean applyDefault) throws MapperParsingException {
|
|
|
String defaultMappingSource;
|
|
|
if (PercolatorFieldMapper.TYPE_NAME.equals(mappingType)) {
|