From f02f63cf755a13bc7cefdb805dd4824afd552039 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 13 May 2011 14:52:09 +0300 Subject: [PATCH] Mapping: dynamic templates of object type do not initialize some mapping data structures (like analyzers lookup), closes #929. --- .../index/mapper/xcontent/ObjectMapper.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java index a810dd6c97a..8135557a5e6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java @@ -336,7 +336,7 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper { } } - private void serializeObject(ParseContext context, String currentFieldName) throws IOException { + private void serializeObject(final ParseContext context, String currentFieldName) throws IOException { context.path().add(currentFieldName); XContentMapper objectMapper = mappers.get(currentFieldName); @@ -367,6 +367,14 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper { objectMapper = builder.build(builderContext); putMapper(objectMapper); + // we need to traverse in case we have a dynamic template and need to add field mappers + // introduced by it + objectMapper.traverse(new FieldMapperListener() { + @Override public void fieldMapper(FieldMapper fieldMapper) { + context.docMapper().addFieldMapper(fieldMapper); + } + }); + // now re add it and parse... context.path().add(currentFieldName); objectMapper.parse(context);