Skip to content

Commit

Permalink
Support allow_duplicates on append processor (#5208)
Browse files Browse the repository at this point in the history
* Support allow_duplicates on append processor

Related to elastic/elasticsearch#61916
  • Loading branch information
stevejgordon authored Jan 7, 2021
1 parent 42eb617 commit 2b75c5e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/Nest/Ingest/Processors/AppendProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ public interface IAppendProcessor : IProcessor

[DataMember(Name ="value")]
IEnumerable<object> Value { get; set; }

[DataMember(Name = "allow_duplicates")]
bool? AllowDuplicates { get; set; }
}

public class AppendProcessor : ProcessorBase, IAppendProcessor
{
public Field Field { get; set; }
public IEnumerable<object> Value { get; set; }
public bool? AllowDuplicates { get; set; }

protected override string Name => "append";
}

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

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

Expand All @@ -49,5 +55,7 @@ public AppendProcessorDescriptor<T> Value<TValue>(params TValue[] values) => Ass
a.Value = (v.First() as IEnumerable)?.Cast<object>();
else a.Value = v?.Cast<object>();
});

public AppendProcessorDescriptor<T> AllowDuplicates(bool? allowDuplicates = true) => Assign(allowDuplicates, (a, v) => a.AllowDuplicates = v);
}
}
32 changes: 22 additions & 10 deletions tests/Tests/Ingest/ProcessorAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,22 +57,33 @@ public static IPromise<IList<IProcessor>> Fluent(ProcessorsDescriptor d)
foreach (var a in All) a.Fluent(d);
return d;
}

public class Append : ProcessorAssertion
{
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent => d => d
.Append<Project>(a => a
.Field(p => p.State)
.Value(StateOfBeing.Stable, StateOfBeing.VeryActive)
);
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent =>
d => d.Append<Project>(a => a.Field(p => p.State).Value(StateOfBeing.Stable, StateOfBeing.VeryActive));

public override IProcessor Initializer => new AppendProcessor
public override IProcessor Initializer => new AppendProcessor { Field = "state", Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }};

public override object Json => new
{
Field = "state",
Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }
field = "state",
value = new[] { "Stable", "VeryActive" }
};

public override object Json => new { field = "state", value = new[] { "Stable", "VeryActive" } };
public override string Key => "append";
}

[SkipVersion("<7.11.0", "Allow duplicates added in 7.11")]
public class AppendWithAllowDuplicates : ProcessorAssertion
{
public override Func<ProcessorsDescriptor, IPromise<IList<IProcessor>>> Fluent =>
d => d.Append<Project>(a => a.Field(p => p.State).Value(StateOfBeing.Stable, StateOfBeing.VeryActive).AllowDuplicates(false));

public override IProcessor Initializer => new AppendProcessor { Field = "state", Value = new object[] { StateOfBeing.Stable, StateOfBeing.VeryActive }, AllowDuplicates = false };

public override object Json => new { field = "state", value = new[] { "Stable", "VeryActive" }, allow_duplicates = false };

public override string Key => "append";
}

Expand Down

0 comments on commit 2b75c5e

Please sign in to comment.