|
@@ -19,14 +19,6 @@
|
|
|
|
|
|
package org.elasticsearch.ingest.common;
|
|
|
|
|
|
-import org.elasticsearch.ingest.CompoundProcessor;
|
|
|
-import org.elasticsearch.ingest.IngestDocument;
|
|
|
-import org.elasticsearch.ingest.Processor;
|
|
|
-import org.elasticsearch.ingest.TestProcessor;
|
|
|
-import org.elasticsearch.ingest.TestTemplateService;
|
|
|
-import org.elasticsearch.script.TemplateScript;
|
|
|
-import org.elasticsearch.test.ESTestCase;
|
|
|
-
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
@@ -34,7 +26,15 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
+import org.elasticsearch.ingest.CompoundProcessor;
|
|
|
+import org.elasticsearch.ingest.IngestDocument;
|
|
|
+import org.elasticsearch.ingest.Processor;
|
|
|
+import org.elasticsearch.ingest.TestProcessor;
|
|
|
+import org.elasticsearch.ingest.TestTemplateService;
|
|
|
+import org.elasticsearch.script.TemplateScript;
|
|
|
+import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
+import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class ForEachProcessorTests extends ESTestCase {
|
|
@@ -49,7 +49,8 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
);
|
|
|
|
|
|
ForEachProcessor processor = new ForEachProcessor(
|
|
|
- "_tag", "values", new UppercaseProcessor("_tag", "_ingest._value", false, "_ingest._value")
|
|
|
+ "_tag", "values", new UppercaseProcessor("_tag", "_ingest._value", false, "_ingest._value"),
|
|
|
+ false
|
|
|
);
|
|
|
processor.execute(ingestDocument);
|
|
|
|
|
@@ -69,7 +70,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
throw new RuntimeException("failure");
|
|
|
}
|
|
|
});
|
|
|
- ForEachProcessor processor = new ForEachProcessor("_tag", "values", testProcessor);
|
|
|
+ ForEachProcessor processor = new ForEachProcessor("_tag", "values", testProcessor, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("exception expected");
|
|
@@ -89,7 +90,8 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
});
|
|
|
Processor onFailureProcessor = new TestProcessor(ingestDocument1 -> {});
|
|
|
processor = new ForEachProcessor(
|
|
|
- "_tag", "values", new CompoundProcessor(false, Arrays.asList(testProcessor), Arrays.asList(onFailureProcessor))
|
|
|
+ "_tag", "values", new CompoundProcessor(false, Arrays.asList(testProcessor), Arrays.asList(onFailureProcessor)),
|
|
|
+ false
|
|
|
);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(testProcessor.getInvokedCounter(), equalTo(3));
|
|
@@ -109,7 +111,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
id.setFieldValue("_ingest._value.type", id.getSourceAndMetadata().get("_type"));
|
|
|
id.setFieldValue("_ingest._value.id", id.getSourceAndMetadata().get("_id"));
|
|
|
});
|
|
|
- ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor);
|
|
|
+ ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
|
|
|
assertThat(innerProcessor.getInvokedCounter(), equalTo(2));
|
|
@@ -137,7 +139,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
ForEachProcessor processor = new ForEachProcessor(
|
|
|
"_tag", "values", new SetProcessor("_tag",
|
|
|
new TestTemplateService.MockTemplateScript.Factory("_ingest._value.new_field"),
|
|
|
- (model) -> model.get("other")));
|
|
|
+ (model) -> model.get("other")), false);
|
|
|
processor.execute(ingestDocument);
|
|
|
|
|
|
assertThat(ingestDocument.getFieldValue("values.0.new_field", String.class), equalTo("value"));
|
|
@@ -174,7 +176,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
"_index", "_type", "_id", null, null, null, Collections.singletonMap("values", values)
|
|
|
);
|
|
|
|
|
|
- ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor);
|
|
|
+ ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<String> result = ingestDocument.getFieldValue("values", List.class);
|
|
@@ -199,7 +201,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
"_tag", "values", new CompoundProcessor(false,
|
|
|
Collections.singletonList(new UppercaseProcessor("_tag_upper", "_ingest._value", false, "_ingest._value")),
|
|
|
Collections.singletonList(new AppendProcessor("_tag", template, (model) -> (Collections.singletonList("added"))))
|
|
|
- ));
|
|
|
+ ), false);
|
|
|
processor.execute(ingestDocument);
|
|
|
|
|
|
List result = ingestDocument.getFieldValue("values", List.class);
|
|
@@ -225,7 +227,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
|
|
|
TestProcessor processor = new TestProcessor(doc -> doc.setFieldValue("_ingest._value",
|
|
|
doc.getFieldValue("_source._value", String.class)));
|
|
|
- ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor);
|
|
|
+ ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor, false);
|
|
|
forEachProcessor.execute(ingestDocument);
|
|
|
|
|
|
List result = ingestDocument.getFieldValue("values", List.class);
|
|
@@ -258,7 +260,7 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_ingest._value", String.class).toUpperCase(Locale.ENGLISH))
|
|
|
);
|
|
|
ForEachProcessor processor = new ForEachProcessor(
|
|
|
- "_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor));
|
|
|
+ "_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor, false), false);
|
|
|
processor.execute(ingestDocument);
|
|
|
|
|
|
List result = ingestDocument.getFieldValue("values1.0.values2", List.class);
|
|
@@ -270,4 +272,16 @@ public class ForEachProcessorTests extends ESTestCase {
|
|
|
assertThat(result.get(1), equalTo("JKL"));
|
|
|
}
|
|
|
|
|
|
+ public void testIgnoreMissing() throws Exception {
|
|
|
+ IngestDocument originalIngestDocument = new IngestDocument(
|
|
|
+ "_index", "_type", "_id", null, null, null, Collections.emptyMap()
|
|
|
+ );
|
|
|
+ IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
+ TestProcessor testProcessor = new TestProcessor(doc -> {});
|
|
|
+ ForEachProcessor processor = new ForEachProcessor("_tag", "_ingest._value", testProcessor, true);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
+ assertThat(testProcessor.getInvokedCounter(), equalTo(0));
|
|
|
+ }
|
|
|
+
|
|
|
}
|