From 252ba57703bcead222fbcc328e4cd910e7de6d09 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 13 Aug 2011 13:08:12 +0300 Subject: [PATCH] Date detection for `YYYY/MM/dd` or `YYYY/MM/dd HH:mm:ss` without timezones now broken, closes #1241. --- .../index/mapper/object/RootObjectMapper.java | 2 +- .../index/mapper/date/SimpleDateMappingTests.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java index 25f51463719..d4e1e391eed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/object/RootObjectMapper.java @@ -51,7 +51,7 @@ public class RootObjectMapper extends ObjectMapper { public static final FormatDateTimeFormatter[] DYNAMIC_DATE_TIME_FORMATTERS = new FormatDateTimeFormatter[]{ DateFieldMapper.Defaults.DATE_TIME_FORMATTER, - Joda.forPattern("yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z") + Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd") }; public static final boolean DATE_DETECTION = true; public static final boolean NUMERIC_DETECTION = false; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java index 9c31b07e07d..1bae0b32012 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/date/SimpleDateMappingTests.java @@ -42,12 +42,21 @@ public class SimpleDateMappingTests { ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder() .startObject() - .field("date_field", "2011/01/22 00:00:00 +02") + .field("date_field1", "2011/01/22") + .field("date_field2", "2011/01/22 00:00:00") +// .field("date_field3", "2011/01/22 +02") +// .field("date_field4", "2011/01/22 00:00:00 +02:00") .endObject() .copiedBytes()); - FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field"); + FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field1"); assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); + fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field2"); + assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); +// fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field3"); +// assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); +// fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field4"); +// assertThat(fieldMapper, instanceOf(DateFieldMapper.class)); } @Test public void testTimestampAsDate() throws Exception {