Search in sources :

Example 31 with Processor

use of org.elasticsearch.ingest.Processor 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 32 with Processor

use of org.elasticsearch.ingest.Processor 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 33 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class GsubProcessorTests method testGsubNullValue.

public void testGsubNullValue() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
    Processor processor = new GsubProcessor(randomAsciiOfLength(10), "field", Pattern.compile("\\."), "-");
    try {
        processor.execute(ingestDocument);
        fail("processor execution should have failed");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), equalTo("field [field] is null, cannot match pattern."));
    }
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 34 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class KeyValueProcessorTests method testIncludeKeys.

public void testIncludeKeys() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
    String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), fieldName, "&", "=", Collections.singletonList("first"), "target", false);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
    assertFalse(ingestDocument.hasField("target.second"));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Example 35 with Processor

use of org.elasticsearch.ingest.Processor in project elasticsearch by elastic.

the class KeyValueProcessorTests method testNonExistentWithIgnoreMissing.

public void testNonExistentWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), "unknown", "", "", null, "target", true);
    processor.execute(ingestDocument);
    assertIngestDocument(originalIngestDocument, ingestDocument);
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument)

Aggregations

Processor (org.elasticsearch.ingest.Processor)101 IngestDocument (org.elasticsearch.ingest.IngestDocument)97 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)57 Matchers.containsString (org.hamcrest.Matchers.containsString)48 ArrayList (java.util.ArrayList)25 List (java.util.List)24 HashMap (java.util.HashMap)13 SortOrder (org.elasticsearch.ingest.common.SortProcessor.SortOrder)11 TestProcessor (org.elasticsearch.ingest.TestProcessor)7 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)6 Map (java.util.Map)5 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)5 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)4 Type (org.elasticsearch.ingest.common.ConvertProcessor.Type)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Locale (java.util.Locale)3 TemplateService (org.elasticsearch.ingest.TemplateService)3 ESTestCase (org.elasticsearch.test.ESTestCase)3 Matchers.equalTo (org.hamcrest.Matchers.equalTo)3