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