Skip to content

Commit ef0e678

Browse files
committed
ingest: date processor should not fail if timestamp is specified as json number
Closes #26967
1 parent 0b0dbad commit ef0e678

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateIndexNameProcessor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ public final class DateIndexNameProcessor extends AbstractProcessor {
6363
@Override
6464
public void execute(IngestDocument ingestDocument) throws Exception {
6565
// Date can be specified as a string or long:
66-
String date = Objects.toString(ingestDocument.getFieldValue(field, Object.class));
66+
Object obj = ingestDocument.getFieldValue(field, Object.class);
67+
String date = null;
68+
if (obj != null) {
69+
// Not use Objects.toString(...) here, because null gets changed to "null" which may confuse some date parsers
70+
date = obj.toString();
71+
}
6772

6873
DateTime dateTime = null;
6974
Exception lastException = null;

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import org.joda.time.format.ISODateTimeFormat;
3131

3232
import java.util.ArrayList;
33-
import java.util.IllformedLocaleException;
3433
import java.util.List;
3534
import java.util.Locale;
3635
import java.util.Map;
36+
import java.util.Objects;
3737
import java.util.function.Function;
3838

3939
public final class DateProcessor extends AbstractProcessor {
@@ -64,7 +64,12 @@ public final class DateProcessor extends AbstractProcessor {
6464

6565
@Override
6666
public void execute(IngestDocument ingestDocument) {
67-
String value = ingestDocument.getFieldValue(field, String.class);
67+
Object obj = ingestDocument.getFieldValue(field, Object.class);
68+
String value = null;
69+
if (obj != null) {
70+
// Not use Objects.toString(...) here, because null gets changed to "null" which may confuse some date parsers
71+
value = obj.toString();
72+
}
6873

6974
DateTime dateTime = null;
7075
Exception lastException = null;

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public void testUnixMs() {
134134
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
135135
dateProcessor.execute(ingestDocument);
136136
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
137+
138+
document = new HashMap<>();
139+
document.put("date_as_string", 1000500L);
140+
ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
141+
dateProcessor.execute(ingestDocument);
142+
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
137143
}
138144

139145
public void testUnix() {

0 commit comments

Comments
 (0)