Skip to content

Commit

Permalink
Explicit _timestamp default null is set to now
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dadoonet committed Jan 26, 2015
1 parent f6e224c commit 932552d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ private void initMappers(Map<String, Object> withoutType) {
path = fieldNode.toString();
} else if (fieldName.equals("format")) {
format = fieldNode.toString();
} else if (fieldName.equals("default") && fieldNode != null) {
defaultTimestamp = fieldNode.toString();
} else if (fieldName.equals("default")) {
defaultTimestamp = fieldNode == null ? null : fieldNode.toString();
}
}
this.timestamp = new Timestamp(enabled, path, format, defaultTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,9 @@ public void testInitMappers() throws IOException {
.endObject()
.endObject().endObject().string();
// This was causing a NPE
new MappingMetaData(new CompressedString(mapping));
MappingMetaData mappingMetaData = new MappingMetaData(new CompressedString(mapping));
String defaultTimestamp = mappingMetaData.timestamp().defaultTimestamp();
assertThat(defaultTimestamp, is(nullValue()));
}

@Test
Expand Down

0 comments on commit 932552d

Please sign in to comment.