diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvProcessor.java index 72dffac1053ff..746a800b764d9 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvProcessor.java @@ -68,7 +68,7 @@ public IngestDocument execute(IngestDocument ingestDocument) { } String line = ingestDocument.getFieldValue(field, String.class, ignoreMissing); - if (line == null && ignoreMissing == false) { + if (line == null && ignoreMissing) { return ingestDocument; } else if (line == null) { throw new IllegalArgumentException("field [" + field + "] is null, cannot process it."); diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CsvProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CsvProcessorTests.java index 45f00a7435033..9e0a2b683e3ff 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CsvProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CsvProcessorTests.java @@ -158,7 +158,7 @@ public void testEmptyFields() throws Exception { items.keySet().stream().skip(numItems - 1).forEach(key -> assertFalse(ingestDocument.hasField(key))); } - public void testWrongStings() throws Exception { + public void testWrongStrings() throws Exception { assumeTrue("single run only", quote.isEmpty()); expectThrows(IllegalArgumentException.class, () -> processDocument(new String[]{"a"}, "abc\"abc")); expectThrows(IllegalArgumentException.class, () -> processDocument(new String[]{"a"}, "\"abc\"asd")); @@ -190,6 +190,19 @@ public void testUntrimmed() throws Exception { assertFalse(document.hasField("f")); } + public void testIgnoreMissing() { + assumeTrue("single run only", quote.isEmpty()); + IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); + String fieldName = randomAlphaOfLength(5); + if (ingestDocument.hasField(fieldName)) { + ingestDocument.removeField(fieldName); + } + CsvProcessor processor = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', true); + processor.execute(ingestDocument); + CsvProcessor processor2 = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', false); + expectThrows(IllegalArgumentException.class, () -> processor2.execute(ingestDocument)); + } + public void testEmptyHeaders() throws Exception { assumeTrue("single run only", quote.isEmpty()); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());