-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ParentAggregation.cs
40 lines (32 loc) · 1.23 KB
/
ParentAggregation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[ContractJsonConverter(typeof(AggregationJsonConverter<ParentAggregation>))]
public interface IParentAggregation : IBucketAggregation
{
/// <summary>
/// The type for the child in the parent/child relationship
/// </summary>
[JsonProperty("type")]
RelationName Type { get; set; }
}
public class ParentAggregation : BucketAggregationBase, IParentAggregation
{
internal ParentAggregation() { }
public ParentAggregation(string name, RelationName type) : base(name) => Type = type;
public RelationName Type { get; set; }
internal override void WrapInContainer(AggregationContainer c) => c.Parent = this;
}
public class ParentAggregationDescriptor<T, TParent>
: BucketAggregationDescriptorBase<ParentAggregationDescriptor<T, TParent>, IParentAggregation, TParent>, IParentAggregation
where T : class
where TParent : class
{
RelationName IParentAggregation.Type { get; set; } = typeof(T);
public ParentAggregationDescriptor<T, TParent> Type(RelationName type) =>
Assign(a => a.Type = type);
public ParentAggregationDescriptor<T, TParent> Type<TOtherParent>() =>
Assign(a => a.Type = typeof(TOtherParent));
}
}