@@ -407,10 +407,7 @@ private static void innerParseObject(ParseContext context, ObjectMapper mapper,
407
407
if (token == XContentParser .Token .FIELD_NAME ) {
408
408
currentFieldName = parser .currentName ();
409
409
paths = splitAndValidatePath (currentFieldName );
410
- if (context .mapperService ().isMetadataField (context .path ().pathAsText (currentFieldName ))) {
411
- throw new MapperParsingException ("Field [" + currentFieldName + "] is a metadata field and cannot be added inside"
412
- + " a document. Use the index API request parameters." );
413
- } else if (containsDisabledObjectMapper (mapper , paths )) {
410
+ if (containsDisabledObjectMapper (mapper , paths )) {
414
411
parser .nextToken ();
415
412
parser .skipChildren ();
416
413
}
@@ -499,7 +496,7 @@ private static void parseObject(final ParseContext context, ObjectMapper mapper,
499
496
String [] paths ) throws IOException {
500
497
assert currentFieldName != null ;
501
498
502
- Mapper objectMapper = getMapper (mapper , currentFieldName , paths );
499
+ Mapper objectMapper = getMapper (context , mapper , currentFieldName , paths );
503
500
if (objectMapper != null ) {
504
501
context .path ().add (currentFieldName );
505
502
parseObjectOrField (context , objectMapper );
@@ -536,7 +533,7 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
536
533
String [] paths ) throws IOException {
537
534
String arrayFieldName = lastFieldName ;
538
535
539
- Mapper mapper = getMapper (parentMapper , lastFieldName , paths );
536
+ Mapper mapper = getMapper (context , parentMapper , lastFieldName , paths );
540
537
if (mapper != null ) {
541
538
// There is a concrete mapper for this field already. Need to check if the mapper
542
539
// expects an array, if so we pass the context straight to the mapper and if not
@@ -613,7 +610,7 @@ private static void parseValue(final ParseContext context, ObjectMapper parentMa
613
610
throw new MapperParsingException ("object mapping [" + parentMapper .name () + "] trying to serialize a value with"
614
611
+ " no field associated with it, current value [" + context .parser ().textOrNull () + "]" );
615
612
}
616
- Mapper mapper = getMapper (parentMapper , currentFieldName , paths );
613
+ Mapper mapper = getMapper (context , parentMapper , currentFieldName , paths );
617
614
if (mapper != null ) {
618
615
parseObjectOrField (context , mapper );
619
616
} else {
@@ -630,7 +627,7 @@ private static void parseValue(final ParseContext context, ObjectMapper parentMa
630
627
private static void parseNullValue (ParseContext context , ObjectMapper parentMapper , String lastFieldName ,
631
628
String [] paths ) throws IOException {
632
629
// we can only handle null values if we have mappings for them
633
- Mapper mapper = getMapper (parentMapper , lastFieldName , paths );
630
+ Mapper mapper = getMapper (context , parentMapper , lastFieldName , paths );
634
631
if (mapper != null ) {
635
632
// TODO: passing null to an object seems bogus?
636
633
parseObjectOrField (context , mapper );
@@ -898,9 +895,16 @@ private static ObjectMapper.Dynamic dynamicOrDefault(ObjectMapper parentMapper,
898
895
}
899
896
900
897
// looks up a child mapper, but takes into account field names that expand to objects
901
- private static Mapper getMapper (ObjectMapper objectMapper , String fieldName , String [] subfields ) {
898
+ private static Mapper getMapper (final ParseContext context , ObjectMapper objectMapper , String fieldName , String [] subfields ) {
899
+ String fieldPath = context .path ().pathAsText (fieldName );
900
+ // Check if mapper is a metadata mapper first
901
+ Mapper mapper = context .docMapper ().mapping ().getMetadataMapper (fieldPath );
902
+ if (mapper != null ) {
903
+ return mapper ;
904
+ }
905
+
902
906
for (int i = 0 ; i < subfields .length - 1 ; ++i ) {
903
- Mapper mapper = objectMapper .getMapper (subfields [i ]);
907
+ mapper = objectMapper .getMapper (subfields [i ]);
904
908
if (mapper == null || (mapper instanceof ObjectMapper ) == false ) {
905
909
return null ;
906
910
}
0 commit comments