forked from elastic/elasticsearch-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRangeAggregationDescriptor.cs
79 lines (64 loc) · 2.17 KB
/
RangeAggregationDescriptor.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Nest.Resolvers.Converters;
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeConverter<RangeAggregator>))]
public interface IRangeAggregator : IBucketAggregator
{
[JsonProperty("field")]
PropertyPathMarker Field { get; set; }
[JsonProperty("script")]
string Script { get; set; }
[JsonProperty("params")]
FluentDictionary<string, object> Params { get; set; }
[JsonProperty(PropertyName = "ranges")]
IEnumerable<Range<double>> Ranges { get; set; }
}
public class RangeAggregator : BucketAggregator, IRangeAggregator
{
public PropertyPathMarker Field { get; set; }
public string Script { get; set; }
public FluentDictionary<string, object> Params { get; set; }
public IEnumerable<Range<double>> Ranges { get; set; }
}
public class RangeAggregationDescriptor<T> : BucketAggregationBaseDescriptor<RangeAggregationDescriptor<T>, T>, IRangeAggregator
where T : class
{
private IRangeAggregator Self { get { return this; } }
PropertyPathMarker IRangeAggregator.Field { get; set; }
string IRangeAggregator.Script { get; set; }
FluentDictionary<string, object> IRangeAggregator.Params { get; set; }
IEnumerable<Range<double>> IRangeAggregator.Ranges { get; set; }
public RangeAggregationDescriptor<T> Field(string field)
{
Self.Field = field;
return this;
}
public RangeAggregationDescriptor<T> Field(Expression<Func<T, object>> field)
{
Self.Field = field;
return this;
}
public RangeAggregationDescriptor<T> Script(string script)
{
Self.Script = script;
return this;
}
public RangeAggregationDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramSelector)
{
Self.Params = paramSelector(new FluentDictionary<string, object>());
return this;
}
public RangeAggregationDescriptor<T> Ranges(params Func<Range<double>, Range<double>>[] ranges)
{
var newRanges = from range in ranges let r = new Range<double>() select range(r);
Self.Ranges = newRanges;
return this;
}
}
}