Skip to content

Commit e89b84d

Browse files
committed
Changed runtime field validation to be done in one place: RuntimeField.parseRuntimeFields.
Removed checks from RootObjectMapper and IndexService. This checks both query-time and index-time runtime field mappings.
1 parent d9faa33 commit e89b84d

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

server/src/main/java/org/elasticsearch/index/IndexService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,11 +1409,6 @@ public static Map<String, MappedFieldType> parseRuntimeMappings(
14091409
// TODO add specific tests to SearchExecutionTests similar to the ones in FieldTypeLookupTests
14101410
MappingParserContext parserContext = mapperService.parserContext();
14111411
Map<String, RuntimeField> runtimeFields = RuntimeField.parseRuntimeFields(new HashMap<>(runtimeMappings), parserContext, false);
1412-
if (parserContext.getNamespaceValidator() != null) {
1413-
for (String runtimeFieldName : runtimeFields.keySet()) {
1414-
parserContext.getNamespaceValidator().validateNamespace(null, runtimeFieldName);
1415-
}
1416-
}
14171412
Map<String, MappedFieldType> runtimeFieldTypes = RuntimeField.collectFieldTypes(runtimeFields.values());
14181413
if (false == indexSettings.getIndexMetadata().getRoutingPaths().isEmpty()) {
14191414
for (String r : runtimeMappings.keySet()) {

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public static RootObjectMapper.Builder parse(String name, Map<String, Object> no
470470
String fieldName = entry.getKey();
471471
Object fieldNode = entry.getValue();
472472
if (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder)
473-
|| processField(builder, fieldName, fieldNode, parserContext, parserContext.getNamespaceValidator())) {
473+
|| processField(builder, fieldName, fieldNode, parserContext)) {
474474
iterator.remove();
475475
}
476476
}
@@ -482,8 +482,7 @@ private static boolean processField(
482482
RootObjectMapper.Builder builder,
483483
String fieldName,
484484
Object fieldNode,
485-
MappingParserContext parserContext,
486-
RootObjectMapperNamespaceValidator namespaceValidator
485+
MappingParserContext parserContext
487486
) {
488487
if (fieldName.equals("date_formats") || fieldName.equals("dynamic_date_formats")) {
489488
if (fieldNode instanceof List) {
@@ -541,11 +540,6 @@ private static boolean processField(
541540
} else if (fieldName.equals("runtime")) {
542541
if (fieldNode instanceof Map) {
543542
Map<String, RuntimeField> fields = RuntimeField.parseRuntimeFields((Map<String, Object>) fieldNode, parserContext, true);
544-
if (namespaceValidator != null) {
545-
for (String runtimeField : fields.keySet()) {
546-
namespaceValidator.validateNamespace(null, runtimeField);
547-
}
548-
}
549543
builder.addRuntimeFields(fields);
550544
return true;
551545
} else {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ static Map<String, RuntimeField> parseRuntimeFields(
189189
+ " Check the documentation."
190190
);
191191
}
192+
if (parserContext.getNamespaceValidator() != null) {
193+
parserContext.getNamespaceValidator().validateNamespace(null, fieldName);
194+
}
192195
runtimeFields.put(fieldName, builder.apply(typeParser.parse(fieldName, propNode, parserContext)));
193196
propNode.remove("type");
194197
MappingParser.checkNoRemainingFields(fieldName, propNode);

0 commit comments

Comments
 (0)