From be1610ba63ac93fe999f3375cbecd8f0bd1ccc1a Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 13 Jan 2015 09:46:53 +0100 Subject: [PATCH] [Mapper] Using default=null for _timestamp field creates a index loss on restart Step to reproduce: * Create new index and type. ``` DELETE new_index PUT new_index { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": null } } } } ``` * Add a document ``` PUT new_index/power/1 { "foo": "bar" } ``` * Restart cluster ... and **index is missing**... ``` GET new_index ``` Gives IndexMissingException Closes #9223. (cherry picked from commit e654a2c) (cherry picked from commit aef3bc2) --- .../cluster/metadata/MappingMetaData.java | 2 +- .../mapper/timestamp/TimestampMappingTests.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java index 0c7535394be..8afa2c14ac4 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java @@ -354,7 +354,7 @@ public class MappingMetaData { path = fieldNode.toString(); } else if (fieldName.equals("format")) { format = fieldNode.toString(); - } else if (fieldName.equals("default")) { + } else if (fieldName.equals("default") && fieldNode != null) { defaultTimestamp = fieldNode.toString(); } } diff --git a/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java index 735c06432d5..03a05aa7d0b 100644 --- a/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java @@ -632,6 +632,22 @@ public class TimestampMappingTests extends ElasticsearchSingleNodeTest { assertThat(mergeResult.hasConflicts(), is(true)); } + /** + * Test for issue #9223 + */ + @Test + public void testInitMappers() throws IOException { + String mapping = XContentFactory.jsonBuilder().startObject() + .startObject("type") + .startObject("_timestamp") + .field("enabled", true) + .field("default", (String) null) + .endObject() + .endObject().endObject().string(); + // This was causing a NPE + new MappingMetaData(new CompressedString(mapping)); + } + @Test public void testMergePaths() throws Exception { String[] possiblePathValues = {"some_path", "anotherPath", null};