ingest: date processor should not fail if timestamp is specified as json number
Closes #26967
This commit is contained in:
parent
35984a616e
commit
141d1b62e9
|
@ -63,7 +63,12 @@ public final class DateIndexNameProcessor extends AbstractProcessor {
|
|||
@Override
|
||||
public void execute(IngestDocument ingestDocument) throws Exception {
|
||||
// Date can be specified as a string or long:
|
||||
String date = Objects.toString(ingestDocument.getFieldValue(field, Object.class));
|
||||
Object obj = ingestDocument.getFieldValue(field, Object.class);
|
||||
String date = null;
|
||||
if (obj != null) {
|
||||
// Not use Objects.toString(...) here, because null gets changed to "null" which may confuse some date parsers
|
||||
date = obj.toString();
|
||||
}
|
||||
|
||||
DateTime dateTime = null;
|
||||
Exception lastException = null;
|
||||
|
|
|
@ -30,10 +30,10 @@ import org.joda.time.DateTimeZone;
|
|||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IllformedLocaleException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class DateProcessor extends AbstractProcessor {
|
||||
|
@ -64,7 +64,12 @@ public final class DateProcessor extends AbstractProcessor {
|
|||
|
||||
@Override
|
||||
public void execute(IngestDocument ingestDocument) {
|
||||
String value = ingestDocument.getFieldValue(field, String.class);
|
||||
Object obj = ingestDocument.getFieldValue(field, Object.class);
|
||||
String value = null;
|
||||
if (obj != null) {
|
||||
// Not use Objects.toString(...) here, because null gets changed to "null" which may confuse some date parsers
|
||||
value = obj.toString();
|
||||
}
|
||||
|
||||
DateTime dateTime = null;
|
||||
Exception lastException = null;
|
||||
|
|
|
@ -134,6 +134,12 @@ public class DateProcessorTests extends ESTestCase {
|
|||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
||||
dateProcessor.execute(ingestDocument);
|
||||
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
||||
|
||||
document = new HashMap<>();
|
||||
document.put("date_as_string", 1000500L);
|
||||
ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
||||
dateProcessor.execute(ingestDocument);
|
||||
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
|
||||
}
|
||||
|
||||
public void testUnix() {
|
||||
|
|
Loading…
Reference in New Issue