ingest: Fix bug that prevent date_index_name processor from accepting timestamps specified as a json number

Closes #26890
This commit is contained in:
Martijn van Groningen 2017-10-06 14:09:35 +02:00
parent 6b53dadcf9
commit bba70205e3
No known key found for this signature in database
GPG Key ID: AB236F4FCF2AF12A
2 changed files with 8 additions and 1 deletions

View File

@ -25,6 +25,7 @@ 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;
import org.elasticsearch.ExceptionsHelper;
@ -61,7 +62,8 @@ public final class DateIndexNameProcessor extends AbstractProcessor {
@Override
public void execute(IngestDocument ingestDocument) throws Exception {
String date = ingestDocument.getFieldValue(field, String.class);
// Date can be specified as a string or long:
String date = Objects.toString(ingestDocument.getFieldValue(field, Object.class));
DateTime dateTime = null;
Exception lastException = null;

View File

@ -62,6 +62,11 @@ public class DateIndexNameProcessorTests extends ESTestCase {
Collections.singletonMap("_field", "1000500"));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{19700101||/m{yyyyMMdd|UTC}}>"));
document = new IngestDocument("_index", "_type", "_id", null, null,
Collections.singletonMap("_field", 1000500L));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{19700101||/m{yyyyMMdd|UTC}}>"));
}
public void testUnix()throws Exception {