Skip to content

Commit ddf32c4

Browse files
committed
Hardcoded hack to get runtime fields with _project mappings to be detected - basic manual tests now pass
1 parent deb416f commit ddf32c4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 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)) {
473+
|| processField(builder, fieldName, fieldNode, parserContext, parserContext.getNamespaceValidator())) {
474474
iterator.remove();
475475
}
476476
}
@@ -482,7 +482,8 @@ private static boolean processField(
482482
RootObjectMapper.Builder builder,
483483
String fieldName,
484484
Object fieldNode,
485-
MappingParserContext parserContext
485+
MappingParserContext parserContext,
486+
RootObjectMapperNamespaceValidator namespaceValidator
486487
) {
487488
if (fieldName.equals("date_formats") || fieldName.equals("dynamic_date_formats")) {
488489
if (fieldNode instanceof List) {
@@ -540,6 +541,16 @@ private static boolean processField(
540541
} else if (fieldName.equals("runtime")) {
541542
if (fieldNode instanceof Map) {
542543
Map<String, RuntimeField> fields = RuntimeField.parseRuntimeFields((Map<String, Object>) fieldNode, parserContext, true);
544+
if (namespaceValidator != null) {
545+
for (String runtimeField : fields.keySet()) {
546+
if ("_project".equals(runtimeField) || runtimeField.startsWith("_project.")) {
547+
throw new IllegalArgumentException(
548+
"Runtime mapping rejected. No mappings of [_project] are allowed in order "
549+
+ "to avoid conflicts with project metadata tags in serverless."
550+
);
551+
}
552+
}
553+
}
543554
builder.addRuntimeFields(fields);
544555
return true;
545556
} else {

0 commit comments

Comments
 (0)