Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default date formats to use underscores via PUT #12509

Merged
merged 1 commit into from Jul 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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