Skip to content

Commit af372a7

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Support allow_duplicates on append processor (#5208)
* Support allow_duplicates on append processor Related to elastic/elasticsearch#61916
1 parent e60aeee commit af372a7

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-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

+22-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
1010
using Nest;
1111
using Tests.Core.Client;
12+
using Tests.Core.Extensions;
1213
using Tests.Core.Xunit;
1314
using Tests.Domain;
1415

@@ -56,22 +57,33 @@ public static IPromise<IList<IProcessor>> Fluent(ProcessorsDescriptor d)
5657
foreach (var a in All) a.Fluent(d);
5758
return d;
5859
}
59-
60+
6061
public class Append : ProcessorAssertion
6162
{
62-
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
63-
.Append<Project>(a => a
64-
.Field(p => p.State)
65-
.Value(StateOfBeing.Stable, StateOfBeing.VeryActive)
66-
);
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));
6765

68-
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
6969
{
70-
Field = "state",
71-
Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }
70+
field = "state",
71+
value = new[] { "Stable", "VeryActive" }
7272
};
7373

74-
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+
7587
public override string Key => "append";
7688
}
7789

0 commit comments

Comments
 (0)