Search in sources :

Example 41 with Processor

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

the class AttachmentProcessorTests method testNullWithoutIgnoreMissing.

public void testNullWithoutIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("source_field", null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new AttachmentProcessor(randomAsciiOfLength(10), "source_field", "randomTarget", null, 10, false);
    Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
    assertThat(exception.getMessage(), equalTo("field [source_field] is null, cannot parse."));
}
Also used : Processor(org.elasticsearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) IOException(java.io.IOException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 42 with Processor

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

the class AttachmentProcessorTests method testNonExistentWithIgnoreMissing.

public void testNonExistentWithIgnoreMissing() throws Exception {
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new AttachmentProcessor(randomAsciiOfLength(10), "source_field", "randomTarget", null, 10, 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)

Example 43 with Processor

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

the class TrackingResultProcessor method decorate.

public static CompoundProcessor decorate(CompoundProcessor compoundProcessor, List<SimulateProcessorResult> processorResultList) {
    List<Processor> processors = new ArrayList<>(compoundProcessor.getProcessors().size());
    for (Processor processor : compoundProcessor.getProcessors()) {
        if (processor instanceof CompoundProcessor) {
            processors.add(decorate((CompoundProcessor) processor, processorResultList));
        } else {
            processors.add(new TrackingResultProcessor(compoundProcessor.isIgnoreFailure(), processor, processorResultList));
        }
    }
    List<Processor> onFailureProcessors = new ArrayList<>(compoundProcessor.getProcessors().size());
    for (Processor processor : compoundProcessor.getOnFailureProcessors()) {
        if (processor instanceof CompoundProcessor) {
            onFailureProcessors.add(decorate((CompoundProcessor) processor, processorResultList));
        } else {
            onFailureProcessors.add(new TrackingResultProcessor(compoundProcessor.isIgnoreFailure(), processor, processorResultList));
        }
    }
    return new CompoundProcessor(compoundProcessor.isIgnoreFailure(), processors, onFailureProcessors);
}
Also used : Processor(org.elasticsearch.ingest.Processor) CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) ArrayList(java.util.ArrayList) CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor)

Example 44 with Processor

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

the class KeyValueProcessorTests method testNullValueWithIgnoreMissing.

public void testNullValueWithIgnoreMissing() throws Exception {
    String fieldName = RandomDocumentPicks.randomFieldName(random());
    IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap(fieldName, null));
    IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), fieldName, "", "", 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)

Example 45 with Processor

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

the class KeyValueProcessorTests method testFailValueSplitMatch.

public void testFailValueSplitMatch() throws Exception {
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("foo", "bar"));
    Processor processor = new KeyValueProcessor(randomAsciiOfLength(10), "foo", "&", "=", null, "target", false);
    Exception exception = expectThrows(IllegalArgumentException.class, () -> processor.execute(ingestDocument));
    assertThat(exception.getMessage(), equalTo("field [foo] does not contain value_split [=]"));
}
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