forked from elastic/elasticsearch-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTermsAggregationDescriptor.cs
156 lines (120 loc) · 4.21 KB
/
TermsAggregationDescriptor.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Nest.Resolvers.Converters;
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeConverter<TermsAggregator>))]
public interface ITermsAggregator : IBucketAggregator
{
[JsonProperty("field")]
PropertyPathMarker Field { get; set; }
[JsonProperty("script")]
string Script { get; set; }
[JsonProperty("size")]
int? Size { get; set; }
[JsonProperty("shard_size")]
int? ShardSize { get; set; }
[JsonProperty("min_doc_count")]
int? MinimumDocumentCount { get; set; }
[JsonProperty("execution_hit")]
TermsAggregationExecutionHint? ExecutionHint { get; set; }
[JsonProperty("order")]
IDictionary<string, string> Order { get; set; }
[JsonProperty("include")]
TermsIncludeExclude Include { get; set; }
[JsonProperty("exclude")]
TermsIncludeExclude Exclude { get; set; }
[JsonProperty("params")]
IDictionary<string, object> Params { get; set; }
}
public class TermsAggregator : BucketAggregator, ITermsAggregator
{
public PropertyPathMarker Field { get; set; }
public string Script { get; set; }
public int? Size { get; set; }
public int? ShardSize { get; set; }
public int? MinimumDocumentCount { get; set; }
public TermsAggregationExecutionHint? ExecutionHint { get; set; }
public IDictionary<string, string> Order { get; set; }
public TermsIncludeExclude Include { get; set; }
public TermsIncludeExclude Exclude { get; set; }
public IDictionary<string, object> Params { get; set; }
}
public class TermsAggregationDescriptor<T> : BucketAggregationBaseDescriptor<TermsAggregationDescriptor<T>, T>, ITermsAggregator where T : class
{
private ITermsAggregator Self { get { return this; } }
PropertyPathMarker ITermsAggregator.Field { get; set; }
string ITermsAggregator.Script { get; set; }
int? ITermsAggregator.Size { get; set; }
int? ITermsAggregator.ShardSize { get; set; }
int? ITermsAggregator.MinimumDocumentCount { get; set; }
TermsAggregationExecutionHint? ITermsAggregator.ExecutionHint { get; set; }
IDictionary<string, string> ITermsAggregator.Order { get; set; }
TermsIncludeExclude ITermsAggregator.Include { get; set; }
TermsIncludeExclude ITermsAggregator.Exclude { get; set; }
IDictionary<string, object> ITermsAggregator.Params { get; set; }
public TermsAggregationDescriptor<T> Field(string field)
{
Self.Field = field;
return this;
}
public TermsAggregationDescriptor<T> Field(Expression<Func<T, object>> field)
{
Self.Field = field;
return this;
}
public TermsAggregationDescriptor<T> Script(string script)
{
Self.Script = script;
return this;
}
public TermsAggregationDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramSelector)
{
Self.Params = paramSelector(new FluentDictionary<string, object>());
return this;
}
public TermsAggregationDescriptor<T> Size(int size)
{
Self.Size = size;
return this;
}
public TermsAggregationDescriptor<T> ShardSize(int shardSize)
{
Self.ShardSize = shardSize;
return this;
}
public TermsAggregationDescriptor<T> MinimumDocumentCount(int minimumDocumentCount)
{
Self.MinimumDocumentCount = minimumDocumentCount;
return this;
}
public TermsAggregationDescriptor<T> ExecutionHint(TermsAggregationExecutionHint executionHint)
{
Self.ExecutionHint = executionHint;
return this;
}
public TermsAggregationDescriptor<T> OrderAscending(string key)
{
Self.Order = new Dictionary<string, string> { {key, "asc"}};
return this;
}
public TermsAggregationDescriptor<T> OrderDescending(string key)
{
Self.Order = new Dictionary<string, string> { {key, "desc"}};
return this;
}
public TermsAggregationDescriptor<T> Include(string includePattern, string regexFlags = null)
{
Self.Include = new TermsIncludeExclude() { Pattern = includePattern, Flags = regexFlags };
return this;
}
public TermsAggregationDescriptor<T> Exclude(string excludePattern, string regexFlags = null)
{
Self.Exclude = new TermsIncludeExclude() { Pattern = excludePattern, Flags = regexFlags };
return this;
}
}
}