Search in sources :

Example 1 with TestProcessor

use of org.opensearch.ingest.TestProcessor in project OpenSearch by opensearch-project.

the class ForEachProcessorFactoryTests method testCreateWithTooManyProcessorTypes.

public void testCreateWithTooManyProcessorTypes() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> {
    });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_first", (r, t, description, c) -> processor);
    registry.put("_second", (r, t, description, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory(scriptService);
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    Map<String, Object> processorTypes = new HashMap<>();
    processorTypes.put("_first", Collections.emptyMap());
    processorTypes.put("_second", Collections.emptyMap());
    config.put("processor", processorTypes);
    Exception exception = expectThrows(OpenSearchParseException.class, () -> forEachFactory.create(registry, null, null, config));
    assertThat(exception.getMessage(), equalTo("[processor] Must specify exactly one processor type"));
}
Also used : TestProcessor(org.opensearch.ingest.TestProcessor) Processor(org.opensearch.ingest.Processor) HashMap(java.util.HashMap) TestProcessor(org.opensearch.ingest.TestProcessor) OpenSearchParseException(org.opensearch.OpenSearchParseException)

Example 2 with TestProcessor

use of org.opensearch.ingest.TestProcessor in project OpenSearch by opensearch-project.

the class ForEachProcessorFactoryTests method testSetIgnoreMissing.

public void testSetIgnoreMissing() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> {
    });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_name", (r, t, description, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory(scriptService);
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("processor", Collections.singletonMap("_name", Collections.emptyMap()));
    config.put("ignore_missing", true);
    ForEachProcessor forEachProcessor = forEachFactory.create(registry, null, null, config);
    assertThat(forEachProcessor, Matchers.notNullValue());
    assertThat(forEachProcessor.getField(), equalTo("_field"));
    assertThat(forEachProcessor.getInnerProcessor(), Matchers.sameInstance(processor));
    assertTrue(forEachProcessor.isIgnoreMissing());
}
Also used : TestProcessor(org.opensearch.ingest.TestProcessor) Processor(org.opensearch.ingest.Processor) HashMap(java.util.HashMap) TestProcessor(org.opensearch.ingest.TestProcessor)

Example 3 with TestProcessor

use of org.opensearch.ingest.TestProcessor in project OpenSearch by opensearch-project.

the class ForEachProcessorFactoryTests method testCreateWithMissingField.

public void testCreateWithMissingField() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> {
    });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_name", (r, t, description, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory(scriptService);
    Map<String, Object> config = new HashMap<>();
    config.put("processor", Collections.singletonList(Collections.singletonMap("_name", Collections.emptyMap())));
    Exception exception = expectThrows(Exception.class, () -> forEachFactory.create(registry, null, null, config));
    assertThat(exception.getMessage(), equalTo("[field] required property is missing"));
}
Also used : TestProcessor(org.opensearch.ingest.TestProcessor) Processor(org.opensearch.ingest.Processor) HashMap(java.util.HashMap) TestProcessor(org.opensearch.ingest.TestProcessor) OpenSearchParseException(org.opensearch.OpenSearchParseException)

Example 4 with TestProcessor

use of org.opensearch.ingest.TestProcessor in project OpenSearch by opensearch-project.

the class ForEachProcessorFactoryTests method testCreate.

public void testCreate() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> {
    });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_name", (r, t, description, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory(scriptService);
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("processor", Collections.singletonMap("_name", Collections.emptyMap()));
    ForEachProcessor forEachProcessor = forEachFactory.create(registry, null, null, config);
    assertThat(forEachProcessor, Matchers.notNullValue());
    assertThat(forEachProcessor.getField(), equalTo("_field"));
    assertThat(forEachProcessor.getInnerProcessor(), Matchers.sameInstance(processor));
    assertFalse(forEachProcessor.isIgnoreMissing());
}
Also used : TestProcessor(org.opensearch.ingest.TestProcessor) Processor(org.opensearch.ingest.Processor) HashMap(java.util.HashMap) TestProcessor(org.opensearch.ingest.TestProcessor)

Example 5 with TestProcessor

use of org.opensearch.ingest.TestProcessor in project OpenSearch by opensearch-project.

the class ForEachProcessorTests method testMetadataAvailable.

public void testMetadataAvailable() throws Exception {
    List<Map<String, Object>> values = new ArrayList<>();
    values.add(new HashMap<>());
    values.add(new HashMap<>());
    IngestDocument ingestDocument = new IngestDocument("_index", "_id", null, null, null, Collections.singletonMap("values", values));
    TestProcessor innerProcessor = new TestProcessor(id -> {
        id.setFieldValue("_ingest._value.index", id.getSourceAndMetadata().get("_index"));
        id.setFieldValue("_ingest._value.type", id.getSourceAndMetadata().get("_type"));
        id.setFieldValue("_ingest._value.id", id.getSourceAndMetadata().get("_id"));
    });
    ForEachProcessor processor = new ForEachProcessor("_tag", null, "values", innerProcessor, false);
    processor.execute(ingestDocument, (result, e) -> {
    });
    assertThat(innerProcessor.getInvokedCounter(), equalTo(2));
    assertThat(ingestDocument.getFieldValue("values.0.index", String.class), equalTo("_index"));
    assertThat(ingestDocument.getFieldValue("values.0.id", String.class), equalTo("_id"));
    assertThat(ingestDocument.getFieldValue("values.1.index", String.class), equalTo("_index"));
    assertThat(ingestDocument.getFieldValue("values.1.id", String.class), equalTo("_id"));
}
Also used : ArrayList(java.util.ArrayList) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) TestProcessor(org.opensearch.ingest.TestProcessor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TestProcessor (org.opensearch.ingest.TestProcessor)22 CompoundProcessor (org.opensearch.ingest.CompoundProcessor)12 Pipeline (org.opensearch.ingest.Pipeline)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 HashMap (java.util.HashMap)8 IngestDocument (org.opensearch.ingest.IngestDocument)8 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)8 Processor (org.opensearch.ingest.Processor)8 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 AbstractProcessor (org.opensearch.ingest.AbstractProcessor)3 DropProcessor (org.opensearch.ingest.DropProcessor)3 OpenSearchParseException (org.opensearch.OpenSearchParseException)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1