|
@@ -392,10 +392,7 @@ final class DocumentParser {
|
|
|
if (token == XContentParser.Token.FIELD_NAME) {
|
|
|
currentFieldName = parser.currentName();
|
|
|
paths = splitAndValidatePath(currentFieldName);
|
|
|
- if (context.mapperService().isMetadataField(context.path().pathAsText(currentFieldName))) {
|
|
|
- throw new MapperParsingException("Field [" + currentFieldName + "] is a metadata field and cannot be added inside"
|
|
|
- + " a document. Use the index API request parameters.");
|
|
|
- } else if (containsDisabledObjectMapper(mapper, paths)) {
|
|
|
+ if (containsDisabledObjectMapper(mapper, paths)) {
|
|
|
parser.nextToken();
|
|
|
parser.skipChildren();
|
|
|
}
|
|
@@ -483,7 +480,7 @@ final class DocumentParser {
|
|
|
String[] paths) throws IOException {
|
|
|
assert currentFieldName != null;
|
|
|
|
|
|
- Mapper objectMapper = getMapper(mapper, currentFieldName, paths);
|
|
|
+ Mapper objectMapper = getMapper(context, mapper, currentFieldName, paths);
|
|
|
if (objectMapper != null) {
|
|
|
context.path().add(currentFieldName);
|
|
|
parseObjectOrField(context, objectMapper);
|
|
@@ -520,7 +517,7 @@ final class DocumentParser {
|
|
|
String[] paths) throws IOException {
|
|
|
String arrayFieldName = lastFieldName;
|
|
|
|
|
|
- Mapper mapper = getMapper(parentMapper, lastFieldName, paths);
|
|
|
+ Mapper mapper = getMapper(context, parentMapper, lastFieldName, paths);
|
|
|
if (mapper != null) {
|
|
|
// There is a concrete mapper for this field already. Need to check if the mapper
|
|
|
// expects an array, if so we pass the context straight to the mapper and if not
|
|
@@ -597,7 +594,7 @@ final class DocumentParser {
|
|
|
throw new MapperParsingException("object mapping [" + parentMapper.name() + "] trying to serialize a value with"
|
|
|
+ " no field associated with it, current value [" + context.parser().textOrNull() + "]");
|
|
|
}
|
|
|
- Mapper mapper = getMapper(parentMapper, currentFieldName, paths);
|
|
|
+ Mapper mapper = getMapper(context, parentMapper, currentFieldName, paths);
|
|
|
if (mapper != null) {
|
|
|
parseObjectOrField(context, mapper);
|
|
|
} else {
|
|
@@ -614,7 +611,7 @@ final class DocumentParser {
|
|
|
private static void parseNullValue(ParseContext context, ObjectMapper parentMapper, String lastFieldName,
|
|
|
String[] paths) throws IOException {
|
|
|
// we can only handle null values if we have mappings for them
|
|
|
- Mapper mapper = getMapper(parentMapper, lastFieldName, paths);
|
|
|
+ Mapper mapper = getMapper(context, parentMapper, lastFieldName, paths);
|
|
|
if (mapper != null) {
|
|
|
// TODO: passing null to an object seems bogus?
|
|
|
parseObjectOrField(context, mapper);
|
|
@@ -882,9 +879,16 @@ final class DocumentParser {
|
|
|
}
|
|
|
|
|
|
// looks up a child mapper, but takes into account field names that expand to objects
|
|
|
- private static Mapper getMapper(ObjectMapper objectMapper, String fieldName, String[] subfields) {
|
|
|
+ private static Mapper getMapper(final ParseContext context, ObjectMapper objectMapper, String fieldName, String[] subfields) {
|
|
|
+ String fieldPath = context.path().pathAsText(fieldName);
|
|
|
+ // Check if mapper is a metadata mapper first
|
|
|
+ Mapper mapper = context.docMapper().mapping().getMetadataMapper(fieldPath);
|
|
|
+ if (mapper != null) {
|
|
|
+ return mapper;
|
|
|
+ }
|
|
|
+
|
|
|
for (int i = 0; i < subfields.length - 1; ++i) {
|
|
|
- Mapper mapper = objectMapper.getMapper(subfields[i]);
|
|
|
+ mapper = objectMapper.getMapper(subfields[i]);
|
|
|
if (mapper == null || (mapper instanceof ObjectMapper) == false) {
|
|
|
return null;
|
|
|
}
|