Skip to content

Commit b95fcd6

Browse files
committed
Explicit _timestamp default null is set to now
When creating an index with: ``` PUT new_index { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": null } } } } ``` When restarting the cluster, `now` is applied instead of `null`. So index become: ``` { "mappings": { "power": { "_timestamp" : { "enabled" : true, "default": "now" } } } } ``` This PR fix that and applies `null` when it was explicitly set. Note that this won't happen anymore in 1.5 as `null` is not allowed anymore as a `default` value. See elastic#9104. See also: * elastic#7036 * elastic#9049 * elastic#9426#issuecomment-71534871
1 parent c799e19 commit b95fcd6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ private void initMappers(Map<String, Object> withoutType) {
354354
path = fieldNode.toString();
355355
} else if (fieldName.equals("format")) {
356356
format = fieldNode.toString();
357-
} else if (fieldName.equals("default") && fieldNode != null) {
358-
defaultTimestamp = fieldNode.toString();
357+
} else if (fieldName.equals("default")) {
358+
defaultTimestamp = fieldNode == null ? null : fieldNode.toString();
359359
}
360360
}
361361
this.timestamp = new Timestamp(enabled, path, format, defaultTimestamp);

src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,9 @@ public void testInitMappers() throws IOException {
624624
.endObject()
625625
.endObject().endObject().string();
626626
// This was causing a NPE
627-
new MappingMetaData(new CompressedString(mapping));
627+
MappingMetaData mappingMetaData = new MappingMetaData(new CompressedString(mapping));
628+
String defaultTimestamp = mappingMetaData.timestamp().defaultTimestamp();
629+
assertThat(defaultTimestamp, is(nullValue()));
628630
}
629631

630632
@Test

0 commit comments

Comments
 (0)