Merge pull request #11002 from jpountz/fix/numeric_resolution_string_date

Mappings: `numeric_resolution` should only apply to dates provided as numbers.
This commit is contained in:
Adrien Grand 2015-05-07 09:39:58 +02:00
commit 80be0f7217
2 changed files with 13 additions and 4 deletions

View File

@ -471,17 +471,18 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
context.allEntries().addText(names.fullName(), dateAsString, boost);
}
value = parseStringValue(dateAsString);
} else if (value != null) {
value = timeUnit.toMillis(value);
}
if (value != null) {
final long timestamp = timeUnit.toMillis(value);
if (fieldType.indexOptions() != IndexOptions.NONE || fieldType.stored()) {
CustomLongNumericField field = new CustomLongNumericField(this, timestamp, fieldType);
CustomLongNumericField field = new CustomLongNumericField(this, value, fieldType);
field.setBoost(boost);
fields.add(field);
}
if (hasDocValues()) {
addDocValue(context, fields, timestamp);
addDocValue(context, fields, value);
}
}
}
@ -549,7 +550,7 @@ public class DateFieldMapper extends NumberFieldMapper<Long> {
return dateTimeFormatter.parser().parseMillis(value);
} catch (RuntimeException e) {
try {
return Long.parseLong(value);
return timeUnit.toMillis(Long.parseLong(value));
} catch (NumberFormatException e1) {
throw new MapperParsingException("failed to parse date field [" + value + "], tried both date format [" + dateTimeFormatter.format() + "], and timestamp number with locale [" + dateTimeFormatter.locale() + "]", e);
}

View File

@ -434,5 +434,13 @@ public class SimpleDateMappingTests extends ElasticsearchSingleNodeTest {
.endObject()
.bytes());
assertThat(getDateAsMillis(doc.rootDoc(), "date_field"), equalTo(43000L));
// but formatted dates still parse as milliseconds
doc = defaultMapper.parse("type", "2", XContentFactory.jsonBuilder()
.startObject()
.field("date_field", "1970-01-01T00:00:44.000Z")
.endObject()
.bytes());
assertThat(getDateAsMillis(doc.rootDoc(), "date_field"), equalTo(44000L));
}
}