Skip to content

Commit cc9bff8

Browse files
committed
ingest: date processor should not fail if timestamp is specified as json number
Closes #26967
1 parent 9325e3c commit cc9bff8

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
@@ -29,10 +29,10 @@
2929
import org.joda.time.format.ISODateTimeFormat;
3030

3131
import java.util.ArrayList;
32-
import java.util.IllformedLocaleException;
3332
import java.util.List;
3433
import java.util.Locale;
3534
import java.util.Map;
35+
import java.util.Objects;
3636
import java.util.function.Function;
3737

3838
public final class DateProcessor extends AbstractProcessor {
@@ -63,7 +63,12 @@ public final class DateProcessor extends AbstractProcessor {
6363

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

6873
DateTime dateTime = null;
6974
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)