Skip to content

Commit 63a3151

Browse files
author
Christoph Büscher
committed
Improve 'ignore_malformed' handling for dates
Currently we occasionally can get ArithmeticException from parsing bad input values on 'date' fields that are passed on even if 'ignore_malformed' is set. This change adds this exception to the ones we already catch for malformed values. Closes elastic#52634
1 parent 7bc6ba3 commit 63a3151

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
518518
} else {
519519
try {
520520
timestamp = fieldType().parse(dateAsString);
521-
} catch (IllegalArgumentException | ElasticsearchParseException | DateTimeException e) {
521+
} catch (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException e) {
522522
if (ignoreMalformed) {
523523
context.addIgnoredField(mappedFieldType.name());
524524
return;

server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ public void testIgnoreMalformed() throws IOException {
167167
"failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]");
168168
testIgnoreMalfomedForValue("-2147483648",
169169
"Invalid value for Year (valid values -999999999 - 999999999): -2147483648");
170+
testIgnoreMalfomedForValue("-522000000", "long overflow");
170171
}
171172

172-
private void testIgnoreMalfomedForValue(String value, String expectedException) throws IOException {
173+
private void testIgnoreMalfomedForValue(String value, String expectedCause) throws IOException {
173174
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
174175
.startObject("properties").startObject("field").field("type", "date").endObject().endObject()
175176
.endObject().endObject());
@@ -185,7 +186,9 @@ private void testIgnoreMalfomedForValue(String value, String expectedException)
185186
.endObject()),
186187
XContentType.JSON));
187188
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
188-
assertThat(e.getCause().getMessage(), containsString(expectedException));
189+
assertThat(e.getMessage(), containsString("failed to parse field [field] of type [date]"));
190+
assertThat(e.getMessage(), containsString("Preview of field's value: '" + value + "'"));
191+
assertThat(e.getCause().getMessage(), containsString(expectedCause));
189192

190193
mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
191194
.startObject("properties").startObject("field").field("type", "date")

0 commit comments

Comments
 (0)