Search in sources :

Example 46 with IngestDocument

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")));
}
Also used : Processor(org.elasticsearch.ingest.Processor) HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 47 with IngestDocument

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."));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 48 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.elasticsearch.ingest.IngestDocument) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 49 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.elasticsearch.ingest.IngestDocument) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 50 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.elasticsearch.ingest.IngestDocument) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Aggregations

IngestDocument (org.elasticsearch.ingest.IngestDocument)170 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)105 Processor (org.elasticsearch.ingest.Processor)97 Matchers.containsString (org.hamcrest.Matchers.containsString)57 HashMap (java.util.HashMap)52 ArrayList (java.util.ArrayList)33 List (java.util.List)27 Map (java.util.Map)22 InputStream (java.io.InputStream)12 GZIPInputStream (java.util.zip.GZIPInputStream)11 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 IOException (java.io.IOException)6 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)6 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Pipeline (org.elasticsearch.ingest.Pipeline)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4