Skip to content

Commit

Permalink
Merge pull request #12509 from metadave/dp_snake_case_dates
Browse files Browse the repository at this point in the history
Default date formats to use underscores via PUT
  • Loading branch information
bookshelfdave committed Jul 28, 2015
2 parents 62c4abd + af17b9c commit dc597f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Expand Up @@ -72,8 +72,8 @@ public class DateFieldMapper extends NumberFieldMapper {
public static final String CONTENT_TYPE = "date";

public static class Defaults extends NumberFieldMapper.Defaults {
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("strictDateOptionalTime||epoch_millis", Locale.ROOT);
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER_BEFORE_2_0 = Joda.forPattern("dateOptionalTime", Locale.ROOT);
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER = Joda.forPattern("strict_date_optional_time||epoch_millis", Locale.ROOT);
public static final FormatDateTimeFormatter DATE_TIME_FORMATTER_BEFORE_2_0 = Joda.forPattern("date_optional_time", Locale.ROOT);
public static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS;
public static final DateFieldType FIELD_TYPE = new DateFieldType();

Expand Down
Expand Up @@ -495,7 +495,7 @@ public void testThatOlderIndicesAllowNonStrictDates() throws Exception {
Version randomVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_0_90_0, Version.V_1_6_1);
IndexService index = createIndex("test", settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build());
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get();
assertDateFormat("epoch_millis||dateOptionalTime");
assertDateFormat("epoch_millis||date_optional_time");
DocumentMapper defaultMapper = index.mapperService().documentMapper("type");

defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -543,13 +543,13 @@ public void testThatNewIndicesOnlyAllowStrictDates() throws Exception {

public void testThatUpgradingAnOlderIndexToStrictDateWorks() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("date_field").field("type", "date").field("format", "dateOptionalTime").endObject().endObject()
.startObject("properties").startObject("date_field").field("type", "date").field("format", "date_optional_time").endObject().endObject()
.endObject().endObject().string();

Version randomVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_0_90_0, Version.V_1_6_1);
createIndex("test", settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build());
client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get();
assertDateFormat("epoch_millis||dateOptionalTime");
assertDateFormat("epoch_millis||date_optional_time");

// index doc
client().prepareIndex("test", "type", "1").setSource(XContentFactory.jsonBuilder()
Expand All @@ -561,12 +561,12 @@ public void testThatUpgradingAnOlderIndexToStrictDateWorks() throws Exception {
String newMapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("date_field")
.field("type", "date")
.field("format", "strictDateOptionalTime||epoch_millis")
.field("format", "strict_date_optional_time||epoch_millis")
.endObject().endObject().endObject().endObject().string();
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type").setSource(newMapping).get();
assertThat(putMappingResponse.isAcknowledged(), is(true));

assertDateFormat("strictDateOptionalTime||epoch_millis");
assertDateFormat("strict_date_optional_time||epoch_millis");
}

private void assertDateFormat(String expectedFormat) throws IOException {
Expand Down

0 comments on commit dc597f0

Please sign in to comment.