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"));
}
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());
}
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"));
}
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());
}
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"));
}
Aggregations