diff --git a/src/Nest/Ingest/Processors/CsvProcessor.cs b/src/Nest/Ingest/Processors/CsvProcessor.cs index 11cb6034c0c..c73327bc5ab 100644 --- a/src/Nest/Ingest/Processors/CsvProcessor.cs +++ b/src/Nest/Ingest/Processors/CsvProcessor.cs @@ -1,10 +1,8 @@ using System; using System.Linq.Expressions; using System.Runtime.Serialization; -using Elasticsearch.Net; using Elasticsearch.Net.Utf8Json; - namespace Nest { /// @@ -52,6 +50,13 @@ public interface ICsvProcessor : IProcessor /// [DataMember(Name = "trim")] bool? Trim { get; set; } + + /// + /// Value used to fill empty fields, empty fields will be skipped if this is not provided. + /// Empty field is one with no value (2 consecutive separators) or empty quotes (`""`) + /// + [DataMember(Name = "empty_value")] + object EmptyValue { get; set; } } /// @@ -70,6 +75,8 @@ public class CsvProcessor : ProcessorBase, ICsvProcessor /// public bool? Trim { get; set; } /// + public object EmptyValue { get; set; } + /// protected override string Name => "csv"; } @@ -84,6 +91,7 @@ public class CsvProcessorDescriptor : ProcessorDescriptorBase public CsvProcessorDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); @@ -110,5 +118,8 @@ public CsvProcessorDescriptor TargetFields(Func, IPromise /// public CsvProcessorDescriptor Separator(string separator) => Assign(separator, (a, v) => a.Separator = v); + + /// + public CsvProcessorDescriptor EmptyValue(object value) => Assign(value, (a, v) => a.EmptyValue = v); } } diff --git a/tests/Tests/Ingest/ProcessorAssertions.cs b/tests/Tests/Ingest/ProcessorAssertions.cs index 41313573bf6..7813411fa89 100644 --- a/tests/Tests/Ingest/ProcessorAssertions.cs +++ b/tests/Tests/Ingest/ProcessorAssertions.cs @@ -77,18 +77,24 @@ public class Csv : ProcessorAssertion .Csv(c => c .Field(p => p.Name) .TargetFields(new[] { "targetField1", "targetField2" }) + .EmptyValue("empty") + .Trim() ); public override IProcessor Initializer => new CsvProcessor { Field = "name", TargetFields = new[] { "targetField1", "targetField2" }, + EmptyValue = "empty", + Trim = true }; public override object Json => new { field = "name", target_fields = new[] { "targetField1", "targetField2" }, + empty_value = "empty", + trim = true }; public override string Key => "csv";