From f3b4c62ee1d02ee6f02ec2d6c8a9f2f7be51fd80 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Tue, 22 Dec 2020 15:46:19 +0000 Subject: [PATCH] Support allow_duplicates on append processor Related to https://github.com/elastic/elasticsearch/pull/61916 --- src/Nest/Ingest/Processors/AppendProcessor.cs | 8 ++++ tests/Tests/Ingest/ProcessorAssertions.cs | 43 ++++++++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/Nest/Ingest/Processors/AppendProcessor.cs b/src/Nest/Ingest/Processors/AppendProcessor.cs index 0e09befb585..cfd0de25d1a 100644 --- a/src/Nest/Ingest/Processors/AppendProcessor.cs +++ b/src/Nest/Ingest/Processors/AppendProcessor.cs @@ -20,12 +20,17 @@ public interface IAppendProcessor : IProcessor [DataMember(Name ="value")] IEnumerable Value { get; set; } + + [DataMember(Name = "allow_duplicates")] + bool? AllowDuplicates { get; set; } } public class AppendProcessor : ProcessorBase, IAppendProcessor { public Field Field { get; set; } public IEnumerable Value { get; set; } + public bool? AllowDuplicates { get; set; } + protected override string Name => "append"; } @@ -35,6 +40,7 @@ public class AppendProcessorDescriptor : ProcessorDescriptorBase "append"; Field IAppendProcessor.Field { get; set; } IEnumerable IAppendProcessor.Value { get; set; } + bool? IAppendProcessor.AllowDuplicates { get; set; } public AppendProcessorDescriptor Field(Field field) => Assign(field, (a, v) => a.Field = v); @@ -49,5 +55,7 @@ public AppendProcessorDescriptor Value(params TValue[] values) => Ass a.Value = (v.First() as IEnumerable)?.Cast(); else a.Value = v?.Cast(); }); + + public AppendProcessorDescriptor AllowDuplicates(bool allowDuplicates = true) => Assign(allowDuplicates, (a, v) => a.AllowDuplicates = v); } } diff --git a/tests/Tests/Ingest/ProcessorAssertions.cs b/tests/Tests/Ingest/ProcessorAssertions.cs index 049587af294..0d5f221bc47 100644 --- a/tests/Tests/Ingest/ProcessorAssertions.cs +++ b/tests/Tests/Ingest/ProcessorAssertions.cs @@ -9,6 +9,7 @@ using Elastic.Elasticsearch.Xunit.XunitPlumbing; using Nest; using Tests.Core.Client; +using Tests.Core.Extensions; using Tests.Core.Xunit; using Tests.Domain; @@ -59,19 +60,41 @@ public static IPromise> Fluent(ProcessorsDescriptor d) public class Append : ProcessorAssertion { - public override Func>> Fluent => d => d - .Append(a => a - .Field(p => p.State) - .Value(StateOfBeing.Stable, StateOfBeing.VeryActive) - ); + public override Func>> Fluent => + d => d.Append(a => + { + var apd = a.Field(p => p.State).Value(StateOfBeing.Stable, StateOfBeing.VeryActive); - public override IProcessor Initializer => new AppendProcessor + if (TestClient.Configuration.InRange(">=7.11.0")) + apd.AllowDuplicates(false); + + return apd; + }); + + public override IProcessor Initializer { - Field = "state", - Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive } - }; + get + { + var ap = new AppendProcessor { Field = "state", Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive } }; + + if (TestClient.Configuration.InRange(">=7.11.0")) + ap.AllowDuplicates = false; + + return ap; + } + } + + public override object Json + { + get + { + if (TestClient.Configuration.InRange(">=7.11.0")) + return new { field = "state", value = new[] { "Stable", "VeryActive" }, allow_duplicates = false }; + + return new { field = "state", value = new[] { "Stable", "VeryActive" } }; + } + } - public override object Json => new { field = "state", value = new[] { "Stable", "VeryActive" } }; public override string Key => "append"; }