use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class RemoveProcessorTests method testRemoveFields.
public void testRemoveFields() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String field = RandomDocumentPicks.randomExistingFieldName(random(), ingestDocument);
Processor processor = new RemoveProcessor(randomAlphaOfLength(10), null, Collections.singletonList(new TestTemplateService.MockTemplateScript.Factory(field)), false);
processor.execute(ingestDocument);
assertThat(ingestDocument.hasField(field), equalTo(false));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DateIndexNameProcessorTests method testUnix.
public void testUnix() throws Exception {
Function<String, ZonedDateTime> function = DateFormat.Unix.getFunction(null, ZoneOffset.UTC, null);
DateIndexNameProcessor dateProcessor = createProcessor("_field", Collections.singletonList(function), ZoneOffset.UTC, "events-", "m", "yyyyMMdd");
IngestDocument document = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("_field", "1000.5"));
dateProcessor.execute(document);
assertThat(document.getSourceAndMetadata().get("_index"), equalTo("<events-{19700101||/m{yyyyMMdd|UTC}}>"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DateProcessorTests method testJavaPatternDefaultYear.
public void testJavaPatternDefaultYear() {
String format = randomFrom("dd/MM", "8dd/MM");
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), null, templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH), "date_as_string", Collections.singletonList(format), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "12/06");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo(ZonedDateTime.now(ZoneId.of("Europe/Amsterdam")).getYear() + "-06-12T00:00:00.000+02:00"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DateProcessorTests method testJavaPattern.
public void testJavaPattern() {
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), null, templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH), "date_as_string", Collections.singletonList("yyyy dd MM HH:mm:ss"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 06 11:05:15");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T11:05:15.000+02:00"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DateProcessorTests method testJavaPatternMultipleFormats.
public void testJavaPatternMultipleFormats() {
List<String> matchFormats = new ArrayList<>();
matchFormats.add("yyyy dd MM");
matchFormats.add("dd/MM/yyyy");
matchFormats.add("dd-MM-yyyy");
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), null, templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ENGLISH), "date_as_string", matchFormats, "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 06");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
document = new HashMap<>();
document.put("date_as_string", "12/06/2010");
ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
document = new HashMap<>();
document.put("date_as_string", "12-06-2010");
ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
document = new HashMap<>();
document.put("date_as_string", "2010");
ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
try {
dateProcessor.execute(ingestDocument);
fail("processor should have failed due to not supported date format");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("unable to parse date [2010]"));
}
}
Aggregations