Skip to content

Commit d9faa33

Browse files
committed
Added namespaceValidator check to IndexService.parseRuntimeMappings
This prevents _project or _project.foo mappings in query-time runtime mappings. For example, these now fail with "Mapping rejected: [_project.foo]. No mappings of [_project] are allowed in order to avoid conflicts with project metadata tags in serverless" GET /blogs/_search { "runtime_mappings": { "_project": { "type": "keyword", "script": { "source": "emit('somevalue')" } } }, "query": { "match_all": {} }, "fields": ["_project"] } GET /blogs/_search { "runtime_mappings": { "_project.foo": { "type": "keyword", "script": { "source": "emit('somevalue')" } } }, "query": { "match_all": {} }, "fields": ["_project.foo"] }
1 parent 17ecfe1 commit d9faa33

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,11 @@ 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+
}
14121417
Map<String, MappedFieldType> runtimeFieldTypes = RuntimeField.collectFieldTypes(runtimeFields.values());
14131418
if (false == indexSettings.getIndexMetadata().getRoutingPaths().isEmpty()) {
14141419
for (String r : runtimeMappings.keySet()) {

0 commit comments

Comments
 (0)