diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index d5cbc8c2849..d59672b98c7 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -587,6 +587,10 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { } } mapper.parse(context); + } else { + if (dynamic == Dynamic.STRICT) { + throw new StrictDynamicMappingException(fullPath, lastFieldName); + } } } diff --git a/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java index b201f32e45c..f09da74caba 100644 --- a/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/dynamic/DynamicMappingTests.java @@ -98,6 +98,17 @@ public class DynamicMappingTests extends ElasticsearchSingleNodeTest { } catch (StrictDynamicMappingException e) { // all is well } + + try { + defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() + .startObject() + .field("field1", "value1") + .field("field2", (String) null) + .bytes()); + fail(); + } catch (StrictDynamicMappingException e) { + // all is well + } } @Test