|
@@ -44,7 +44,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
@Before
|
|
|
public void createStandardProcessor() {
|
|
|
processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 10000, false, null, null);
|
|
|
+ "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 10000, false, null, null, false);
|
|
|
}
|
|
|
|
|
|
public void testEnglishTextDocument() throws Exception {
|
|
@@ -77,7 +77,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
selectedProperties.add(AttachmentProcessor.Property.DATE);
|
|
|
}
|
|
|
processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "target_field", selectedProperties, 10000, false, null, null);
|
|
|
+ "target_field", selectedProperties, 10000, false, null, null, false);
|
|
|
|
|
|
Map<String, Object> attachmentData = parseDocument("htmlWithEmptyDateMeta.html", processor);
|
|
|
assertThat(attachmentData.keySet(), hasSize(selectedFieldNames.length));
|
|
@@ -237,7 +237,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
Collections.singletonMap("source_field", null));
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
Processor processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "randomTarget", null, 10, true, null, null);
|
|
|
+ "randomTarget", null, 10, true, null, null, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
}
|
|
@@ -246,7 +246,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
Processor processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "randomTarget", null, 10, true, null, null);
|
|
|
+ "randomTarget", null, 10, true, null, null, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
}
|
|
@@ -256,7 +256,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
Collections.singletonMap("source_field", null));
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
Processor processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "randomTarget", null, 10, false, null, null);
|
|
|
+ "randomTarget", null, 10, false, null, null, false);
|
|
|
Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
|
|
|
assertThat(exception.getMessage(), equalTo("field [source_field] is null, cannot parse."));
|
|
|
}
|
|
@@ -265,7 +265,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.emptyMap());
|
|
|
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
Processor processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "randomTarget", null, 10, false, null, null);
|
|
|
+ "randomTarget", null, 10, false, null, null, false);
|
|
|
Exception exception = expectThrows(Exception.class, () -> processor.execute(ingestDocument));
|
|
|
assertThat(exception.getMessage(), equalTo("field [source_field] not present as part of path [source_field]"));
|
|
|
}
|
|
@@ -299,7 +299,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
|
|
|
public void testIndexedChars() throws Exception {
|
|
|
processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 19, false, null, null);
|
|
|
+ "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 19, false, null, null, false);
|
|
|
|
|
|
Map<String, Object> attachmentData = parseDocument("text-in-english.txt", processor);
|
|
|
|
|
@@ -310,7 +310,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
assertThat(attachmentData.get("content_length"), is(19L));
|
|
|
|
|
|
processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
- "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 19, false, "max_length", null);
|
|
|
+ "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 19, false, "max_length", null, false);
|
|
|
|
|
|
attachmentData = parseDocument("text-in-english.txt", processor);
|
|
|
|
|
@@ -341,7 +341,7 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
public void testIndexedCharsWithResourceName() throws Exception {
|
|
|
processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
"target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 100,
|
|
|
- false, null, "resource_name");
|
|
|
+ false, null, "resource_name", false);
|
|
|
|
|
|
Map<String, Object> attachmentData = parseDocument("text-cjk-big5.txt", processor, Collections.singletonMap("max_length", 100),
|
|
|
true);
|
|
@@ -369,6 +369,27 @@ public class AttachmentProcessorTests extends ESTestCase {
|
|
|
assertThat(attachmentData.get("content_length"), is(100L));
|
|
|
}
|
|
|
|
|
|
+ public void testRemoveBinary() throws Exception {
|
|
|
+ {
|
|
|
+ // Test the default behavior.
|
|
|
+ Map<String, Object> document = new HashMap<>();
|
|
|
+ document.put("source_field", getAsBinaryOrBase64("text-in-english.txt"));
|
|
|
+ IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertThat(ingestDocument.hasField("source_field"), is(true));
|
|
|
+ }
|
|
|
+ {
|
|
|
+ // Remove the binary field.
|
|
|
+ processor = new AttachmentProcessor(randomAlphaOfLength(10), null, "source_field",
|
|
|
+ "target_field", EnumSet.allOf(AttachmentProcessor.Property.class), 10000, false, null, null, true);
|
|
|
+ Map<String, Object> document = new HashMap<>();
|
|
|
+ document.put("source_field", getAsBinaryOrBase64("text-in-english.txt"));
|
|
|
+ IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertThat(ingestDocument.hasField("source_field"), is(false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Object getAsBinaryOrBase64(String filename) throws Exception {
|
|
|
String path = "/org/elasticsearch/ingest/attachment/test/sample-files/" + filename;
|
|
|
try (InputStream is = AttachmentProcessorTests.class.getResourceAsStream(path)) {
|