use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class SplitProcessorTests method testSplitAppendable.
public void testSplitAppendable() throws Exception {
Map<String, Object> splitConfig = new HashMap<>();
splitConfig.put("field", "flags");
splitConfig.put("separator", "\\|");
Processor splitProcessor = (new SplitProcessor.Factory()).create(null, null, splitConfig);
Map<String, Object> source = new HashMap<>();
source.put("flags", "new|hot|super|fun|interesting");
IngestDocument ingestDocument = new IngestDocument(source, new HashMap<>());
splitProcessor.execute(ingestDocument);
@SuppressWarnings("unchecked") List<String> flags = (List<String>) ingestDocument.getFieldValue("flags", List.class);
assertThat(flags, equalTo(Arrays.asList("new", "hot", "super", "fun", "interesting")));
ingestDocument.appendFieldValue("flags", "additional_flag");
assertThat(ingestDocument.getFieldValue("flags", List.class), equalTo(Arrays.asList("new", "hot", "super", "fun", "interesting", "additional_flag")));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class SplitProcessorTests method testSplitNullValue.
public void testSplitNullValue() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
Processor processor = new SplitProcessor(randomAsciiOfLength(10), "field", "\\.", false);
try {
processor.execute(ingestDocument);
fail("split processor should have failed");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), equalTo("field [field] is null, cannot split."));
}
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class DateProcessorTests method testJodaPattern.
public void testJodaPattern() {
DateProcessor dateProcessor = new DateProcessor(randomAsciiOfLength(10), DateTimeZone.forID("Europe/Amsterdam"), 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.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class DateProcessorTests method testUnixMs.
public void testUnixMs() {
DateProcessor dateProcessor = new DateProcessor(randomAsciiOfLength(10), DateTimeZone.UTC, randomLocale(random()), "date_as_string", Collections.singletonList("UNIX_MS"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "1000500");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("1970-01-01T00:16:40.500Z"));
}
use of org.elasticsearch.ingest.IngestDocument in project elasticsearch by elastic.
the class DateProcessorTests method testJodaPatternLocale.
public void testJodaPatternLocale() {
DateProcessor dateProcessor = new DateProcessor(randomAsciiOfLength(10), DateTimeZone.forID("Europe/Amsterdam"), Locale.ITALIAN, "date_as_string", Collections.singletonList("yyyy dd MMM"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 giugno");
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"));
}
Aggregations