|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.ingest.common;
|
|
|
|
|
|
+import org.elasticsearch.common.util.set.Sets;
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
|
import org.elasticsearch.ingest.Processor;
|
|
|
import org.elasticsearch.ingest.RandomDocumentPicks;
|
|
@@ -36,7 +37,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
public void test() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=", null, "target", false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=", null, null, "target", false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
|
|
|
assertThat(ingestDocument.getFieldValue("target.second", List.class), equalTo(Arrays.asList("world", "universe")));
|
|
@@ -45,7 +46,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
public void testRootTarget() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
ingestDocument.setFieldValue("myField", "first=hello&second=world&second=universe");
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "myField", "&", "=", null, null, false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "myField", "&", "=", null, null,null, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue("first", String.class), equalTo("hello"));
|
|
|
assertThat(ingestDocument.getFieldValue("second", List.class), equalTo(Arrays.asList("world", "universe")));
|
|
@@ -54,7 +55,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
public void testKeySameAsSourceField() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
ingestDocument.setFieldValue("first", "first=hello");
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "first", "&", "=", null, null, false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "first", "&", "=", null, null,null, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue("first", List.class), equalTo(Arrays.asList("first=hello", "hello")));
|
|
|
}
|
|
@@ -63,15 +64,38 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
|
|
|
Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=",
|
|
|
- Collections.singletonList("first"), "target", false);
|
|
|
+ Sets.newHashSet("first"), null, "target", false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
|
|
|
assertFalse(ingestDocument.hasField("target.second"));
|
|
|
}
|
|
|
|
|
|
+ public void testExcludeKeys() throws Exception {
|
|
|
+ IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
+ String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello&second=world&second=universe");
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=",
|
|
|
+ null, Sets.newHashSet("second"), "target", false);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello"));
|
|
|
+ assertFalse(ingestDocument.hasField("target.second"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testIncludeAndExcludeKeys() throws Exception {
|
|
|
+ IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
+ String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument,
|
|
|
+ "first=hello&second=world&second=universe&third=bar");
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=",
|
|
|
+ Sets.newHashSet("first", "second"), Sets.newHashSet("first", "second"), "target", false);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertFalse(ingestDocument.hasField("target.first"));
|
|
|
+ assertFalse(ingestDocument.hasField("target.second"));
|
|
|
+ assertFalse(ingestDocument.hasField("target.third"));
|
|
|
+ }
|
|
|
+
|
|
|
public void testMissingField() {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "unknown", "&", "=", null, "target", false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "unknown", "&",
|
|
|
+ "=", null, null, "target", false);
|
|
|
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> processor.execute(ingestDocument));
|
|
|
assertThat(exception.getMessage(), equalTo("field [unknown] not present as part of path [unknown]"));
|
|
|
}
|
|
@@ -81,7 +105,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(),
|
|
|
Collections.singletonMap(fieldName, null));
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "", "", null, "target", true);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "", "", null, null, "target", true);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
}
|
|
@@ -89,7 +113,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
public void testNonExistentWithIgnoreMissing() throws Exception {
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "unknown", "", "", null, "target", true);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "unknown", "", "", null, null, "target", true);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
}
|
|
@@ -97,7 +121,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
public void testFailFieldSplitMatch() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "first=hello|second=world|second=universe");
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=", null, "target", false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), fieldName, "&", "=", null, null, "target", false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue("target.first", String.class), equalTo("hello|second=world|second=universe"));
|
|
|
assertFalse(ingestDocument.hasField("target.second"));
|
|
@@ -105,7 +129,7 @@ public class KeyValueProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testFailValueSplitMatch() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("foo", "bar"));
|
|
|
- Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "foo", "&", "=", null, "target", false);
|
|
|
+ Processor processor = new KeyValueProcessor(randomAlphaOfLength(10), "foo", "&", "=", null, null, "target", false);
|
|
|
Exception exception = expectThrows(IllegalArgumentException.class, () -> processor.execute(ingestDocument));
|
|
|
assertThat(exception.getMessage(), equalTo("field [foo] does not contain value_split [=]"));
|
|
|
}
|