diff --git a/server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java index b713ecada5237..ab58adff1ce06 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java @@ -75,8 +75,12 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio while (parser.nextToken() != XContentParser.Token.END_OBJECT) { XContentParserUtils.ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser); String fieldName = parser.currentName(); - // TODO: Find the leaf field under objects - Mapper mapper = context.mappingLookup().getMapper(fieldName); + var parent = context.parent().findParentMapper(fieldName); + if (parent == null) { + throw new IllegalArgumentException("Illegal inference field [" + fieldName + "] found."); + } + String suffix = context.parent() != parent ? fieldName.substring(parent.fullPath().length() + 1) : fieldName; + var mapper = parent.getMapper(suffix); if (mapper != null && mapper instanceof InferenceFieldMapper && mapper instanceof FieldMapper fieldMapper) { fieldMapper.parseCreateField(new DocumentParserContext.Wrapper(context.parent(), context) { @Override