Skip to content

Commit 3b44274

Browse files
author
Christoph Büscher
authored
Improve 'ignore_malformed' handling for dates (#60211)
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 #52634
1 parent 39f92f2 commit 3b44274

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
546546
} else {
547547
try {
548548
timestamp = fieldType().parse(dateAsString);
549-
} catch (IllegalArgumentException | ElasticsearchParseException | DateTimeException e) {
549+
} catch (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException e) {
550550
if (ignoreMalformed) {
551551
context.addIgnoredField(mappedFieldType.name());
552552
return;

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ public void testIgnoreMalformed() throws IOException {
175175
"failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]");
176176
testIgnoreMalfomedForValue("-2147483648",
177177
"Invalid value for Year (valid values -999999999 - 999999999): -2147483648");
178+
testIgnoreMalfomedForValue("-522000000", "long overflow");
178179
}
179180

180-
private void testIgnoreMalfomedForValue(String value, String expectedException) throws IOException {
181+
private void testIgnoreMalfomedForValue(String value, String expectedCause) throws IOException {
181182
String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
182183
.startObject("properties").startObject("field").field("type", "date").endObject().endObject()
183184
.endObject().endObject());
@@ -193,7 +194,9 @@ private void testIgnoreMalfomedForValue(String value, String expectedException)
193194
.endObject()),
194195
XContentType.JSON));
195196
MapperParsingException e = expectThrows(MapperParsingException.class, runnable);
196-
assertThat(e.getCause().getMessage(), containsString(expectedException));
197+
assertThat(e.getMessage(), containsString("failed to parse field [field] of type [date]"));
198+
assertThat(e.getMessage(), containsString("Preview of field's value: '" + value + "'"));
199+
assertThat(e.getCause().getMessage(), containsString(expectedCause));
197200

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

0 commit comments

Comments
 (0)