Merge pull request #12977 from jasontedor/fix/12873
Add millisecond parser for dynamic date fields mapped from "yyyy/MM/dd"
This commit is contained in:
commit
66b0e7a6e1
|
@ -275,9 +275,9 @@ public class Joda {
|
||||||
.toFormatter()
|
.toFormatter()
|
||||||
.withZoneUTC();
|
.withZoneUTC();
|
||||||
|
|
||||||
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[] {longFormatter.getParser(), shortFormatter.getParser()});
|
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});
|
||||||
|
|
||||||
return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
|
return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,9 @@ public class SimpleDateMappingTests extends ESSingleNodeTestCase {
|
||||||
|
|
||||||
FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field1");
|
FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field1");
|
||||||
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
|
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
|
||||||
|
DateFieldMapper dateFieldMapper = (DateFieldMapper)fieldMapper;
|
||||||
|
assertEquals("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", dateFieldMapper.fieldType().dateTimeFormatter().format());
|
||||||
|
assertEquals(1265587200000L, dateFieldMapper.fieldType().dateTimeFormatter().parser().parseMillis("1265587200000"));
|
||||||
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field2");
|
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field2");
|
||||||
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
|
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue