Skip to content

Commit b5ef05b

Browse files
committed
Support allow_duplicates on append processor (#5208)
* Support allow_duplicates on append processor Related to elastic/elasticsearch#61916 (cherry picked from commit 2b75c5e)
1 parent f0b2e5d commit b5ef05b

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/Nest/Ingest/Processors/AppendProcessor.cs

+8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ public interface IAppendProcessor : IProcessor
2020

2121
[DataMember(Name ="value")]
2222
IEnumerable<object> Value { get; set; }
23+
24+
[DataMember(Name = "allow_duplicates")]
25+
bool? AllowDuplicates { get; set; }
2326
}
2427

2528
public class AppendProcessor : ProcessorBase, IAppendProcessor
2629
{
2730
public Field Field { get; set; }
2831
public IEnumerable<object> Value { get; set; }
32+
public bool? AllowDuplicates { get; set; }
33+
2934
protected override string Name => "append";
3035
}
3136

@@ -35,6 +40,7 @@ public class AppendProcessorDescriptor<T> : ProcessorDescriptorBase<AppendProces
3540
protected override string Name => "append";
3641
Field IAppendProcessor.Field { get; set; }
3742
IEnumerable<object> IAppendProcessor.Value { get; set; }
43+
bool? IAppendProcessor.AllowDuplicates { get; set; }
3844

3945
public AppendProcessorDescriptor<T> Field(Field field) => Assign(field, (a, v) => a.Field = v);
4046

@@ -49,5 +55,7 @@ public AppendProcessorDescriptor<T> Value<TValue>(params TValue[] values) => Ass
4955
a.Value = (v.First() as IEnumerable)?.Cast<object>();
5056
else a.Value = v?.Cast<object>();
5157
});
58+
59+
public AppendProcessorDescriptor<T> AllowDuplicates(bool? allowDuplicates = true) => Assign(allowDuplicates, (a, v) => a.AllowDuplicates = v);
5260
}
5361
}

tests/Tests/Ingest/ProcessorAssertions.cs

+23-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
1010
using Nest;
1111
using Tests.Core.Client;
12+
using Tests.Core.Extensions;
13+
using Tests.Core.Xunit;
1214
using Tests.Domain;
1315

1416
namespace Tests.Ingest
@@ -55,22 +57,33 @@ public static IPromise<IList<IProcessor>> Fluent(ProcessorsDescriptor d)
5557
foreach (var a in All) a.Fluent(d);
5658
return d;
5759
}
58-
60+
5961
public class Append : ProcessorAssertion
6062
{
61-
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
62-
.Append<Project>(a => a
63-
.Field(p => p.State)
64-
.Value(StateOfBeing.Stable, StateOfBeing.VeryActive)
65-
);
63+
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent =>
64+
d => d.Append<Project>(a => a.Field(p => p.State).Value(StateOfBeing.Stable, StateOfBeing.VeryActive));
6665

67-
public override IProcessor Initializer => new AppendProcessor
66+
public override IProcessor Initializer => new AppendProcessor { Field = "state", Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }};
67+
68+
public override object Json => new
6869
{
69-
Field = "state",
70-
Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }
70+
field = "state",
71+
value = new[] { "Stable", "VeryActive" }
7172
};
7273

73-
public override object Json => new { field = "state", value = new[] { "Stable", "VeryActive" } };
74+
public override string Key => "append";
75+
}
76+
77+
[SkipVersion("<7.11.0", "Allow duplicates added in 7.11")]
78+
public class AppendWithAllowDuplicates : ProcessorAssertion
79+
{
80+
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent =>
81+
d => d.Append<Project>(a => a.Field(p => p.State).Value(StateOfBeing.Stable, StateOfBeing.VeryActive).AllowDuplicates(false));
82+
83+
public override IProcessor Initializer => new AppendProcessor { Field = "state", Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }, AllowDuplicates = false };
84+
85+
public override object Json => new { field = "state", value = new[] { "Stable", "VeryActive" }, allow_duplicates = false };
86+
7487
public override string Key => "append";
7588
}
7689

0 commit comments

Comments
 (0)