1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Threading . Tasks ;
4
+ using Elastic . Clients . Elasticsearch ;
5
+ using Elastic . Clients . Elasticsearch . Aggregations ;
4
6
using Exceptionless . DateTimeExtensions ;
5
7
using Foundatio . Parsers . ElasticQueries . Visitors ;
6
8
using Foundatio . Parsers . LuceneQueries . Extensions ;
7
9
using Foundatio . Parsers . LuceneQueries . Nodes ;
8
10
using Foundatio . Parsers . LuceneQueries . Visitors ;
9
- using Nest ;
10
11
11
12
namespace Foundatio . Parsers . ElasticQueries . Extensions ;
12
13
@@ -15,7 +16,7 @@ public static class DefaultAggregationNodeExtensions
15
16
// NOTE: We may want to read this dynamically from server settings.
16
17
public const int MAX_BUCKET_SIZE = 10000 ;
17
18
18
- public static Task < AggregationBase > GetDefaultAggregationAsync ( this IQueryNode node , IQueryVisitorContext context )
19
+ public static Task < Aggregation > GetDefaultAggregationAsync ( this IQueryNode node , IQueryVisitorContext context )
19
20
{
20
21
if ( node is GroupNode groupNode )
21
22
return groupNode . GetDefaultAggregationAsync ( context ) ;
@@ -26,7 +27,7 @@ public static Task<AggregationBase> GetDefaultAggregationAsync(this IQueryNode n
26
27
return null ;
27
28
}
28
29
29
- public static async Task < AggregationBase > GetDefaultAggregationAsync ( this GroupNode node , IQueryVisitorContext context )
30
+ public static async Task < Aggregation > GetDefaultAggregationAsync ( this GroupNode node , IQueryVisitorContext context )
30
31
{
31
32
if ( context is not IElasticQueryVisitorContext elasticContext )
32
33
throw new ArgumentException ( "Context must be of type IElasticQueryVisitorContext" , nameof ( context ) ) ;
@@ -47,11 +48,11 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this GroupN
47
48
return GetHistogramAggregation ( "histogram_" + originalField , field , node . UnescapedProximity , node . UnescapedBoost , context ) ;
48
49
49
50
case AggregationType . GeoHashGrid :
50
- var precision = GeoHashPrecision . Precision1 ;
51
+ var precision = new GeohashPrecision ( 1 ) ;
51
52
if ( ! String . IsNullOrEmpty ( node . UnescapedProximity ) )
52
53
Enum . TryParse ( node . UnescapedProximity , out precision ) ;
53
54
54
- return new GeoHashGridAggregation ( "geogrid_" + originalField )
55
+ return new Aggregation ( "geogrid_" + originalField , new GeohashGridAggregation
55
56
{
56
57
Field = field ,
57
58
Precision = precision ,
@@ -62,14 +63,14 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this GroupN
62
63
{
63
64
Script = new InlineScript ( $ "doc['{ node . Field } '].lon")
64
65
}
65
- } ;
66
+ } ) ;
66
67
67
68
case AggregationType . Terms :
68
69
var agg = new TermsAggregation ( "terms_" + originalField )
69
70
{
70
71
Field = field ,
71
72
Size = node . GetProximityAsInt32 ( ) ,
72
- MinimumDocumentCount = node . GetBoostAsInt32 ( ) ,
73
+ MinDocCount = node . GetBoostAsInt32 ( ) ,
73
74
Meta = new Dictionary < string , object > { { "@field_type" , property ? . Type } }
74
75
} ;
75
76
@@ -85,7 +86,7 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this GroupN
85
86
return null ;
86
87
}
87
88
88
- public static async Task < AggregationBase > GetDefaultAggregationAsync ( this TermNode node , IQueryVisitorContext context )
89
+ public static async Task < Aggregation > GetDefaultAggregationAsync ( this TermNode node , IQueryVisitorContext context )
89
90
{
90
91
if ( context is not IElasticQueryVisitorContext elasticContext )
91
92
throw new ArgumentException ( "Context must be of type IElasticQueryVisitorContext" , nameof ( context ) ) ;
@@ -134,11 +135,11 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this TermNo
134
135
return GetPercentilesAggregation ( "percentiles_" + originalField , aggField , node . UnescapedProximity , node . UnescapedBoost , context ) ;
135
136
136
137
case AggregationType . GeoHashGrid :
137
- var precision = GeoHashPrecision . Precision1 ;
138
+ var precision = new GeohashPrecision ( 1 ) ;
138
139
if ( ! String . IsNullOrEmpty ( node . UnescapedProximity ) )
139
140
Enum . TryParse ( node . UnescapedProximity , out precision ) ;
140
141
141
- return new GeoHashGridAggregation ( "geogrid_" + originalField )
142
+ return new GeohashGridAggregation ( "geogrid_" + originalField )
142
143
{
143
144
Field = aggField ,
144
145
Precision = precision ,
@@ -156,7 +157,7 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this TermNo
156
157
{
157
158
Field = aggField ,
158
159
Size = node . GetProximityAsInt32 ( ) ,
159
- MinimumDocumentCount = node . GetBoostAsInt32 ( ) ,
160
+ MinDocCount = node . GetBoostAsInt32 ( ) ,
160
161
Meta = new Dictionary < string , object > { { "@field_type" , property ? . Type } }
161
162
} ;
162
163
@@ -169,7 +170,7 @@ public static async Task<AggregationBase> GetDefaultAggregationAsync(this TermNo
169
170
return null ;
170
171
}
171
172
172
- private static AggregationBase GetPercentilesAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
173
+ private static Aggregation GetPercentilesAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
173
174
{
174
175
List < double > percents = null ;
175
176
if ( ! String . IsNullOrWhiteSpace ( proximity ) )
@@ -189,7 +190,7 @@ private static AggregationBase GetPercentilesAggregation(string originalField, s
189
190
} ;
190
191
}
191
192
192
- private static AggregationBase GetHistogramAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
193
+ private static Aggregation GetHistogramAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
193
194
{
194
195
double interval = 50 ;
195
196
if ( Double . TryParse ( proximity , out double prox ) )
@@ -198,25 +199,25 @@ private static AggregationBase GetHistogramAggregation(string originalField, str
198
199
return new HistogramAggregation ( originalField )
199
200
{
200
201
Field = field ,
201
- MinimumDocumentCount = 0 ,
202
+ MinDocCount = 0 ,
202
203
Interval = interval
203
204
} ;
204
205
}
205
206
206
- private static AggregationBase GetDateHistogramAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
207
+ private static Aggregation GetDateHistogramAggregation ( string originalField , string field , string proximity , string boost , IQueryVisitorContext context )
207
208
{
208
209
// NOTE: StartDate and EndDate are set in the Repositories QueryBuilderContext.
209
210
var start = context . GetDate ( "StartDate" ) ;
210
211
var end = context . GetDate ( "EndDate" ) ;
211
212
bool isValidRange = start . HasValue && start . Value > DateTime . MinValue && end . HasValue && end . Value < DateTime . MaxValue && start . Value <= end . Value ;
212
- var bounds = isValidRange ? new ExtendedBounds < DateMath > { Minimum = start . Value , Maximum = end . Value } : null ;
213
+ var bounds = isValidRange ? new ExtendedBoundsDate { Min = start . Value , Max = end . Value } : null ;
213
214
214
215
var interval = GetInterval ( proximity , start , end ) ;
215
216
string timezone = TryConvertTimeUnitToUtcOffset ( boost ) ;
216
217
var agg = new DateHistogramAggregation ( originalField )
217
218
{
218
219
Field = field ,
219
- MinimumDocumentCount = 0 ,
220
+ MinDocCount = 0 ,
220
221
Format = "date_optional_time" ,
221
222
TimeZone = timezone ,
222
223
Meta = ! String . IsNullOrEmpty ( boost ) ? new Dictionary < string , object > { { "@timezone" , boost } } : null ,
@@ -247,55 +248,55 @@ private static string TryConvertTimeUnitToUtcOffset(string boost)
247
248
return "+" + timezoneOffset . Value . ToString ( "hh\\ :mm" ) ;
248
249
}
249
250
250
- private static Union < DateInterval , Time > GetInterval ( string proximity , DateTime ? start , DateTime ? end )
251
+ private static Union < CalendarInterval , Duration > GetInterval ( string proximity , DateTime ? start , DateTime ? end )
251
252
{
252
253
if ( String . IsNullOrEmpty ( proximity ) )
253
254
return GetInterval ( start , end ) ;
254
255
255
256
return proximity . Trim ( ) switch
256
257
{
257
- "s" or "1s" or "second" => DateInterval . Second ,
258
- "m" or "1m" or "minute" => DateInterval . Minute ,
259
- "h" or "1h" or "hour" => DateInterval . Hour ,
260
- "d" or "1d" or "day" => DateInterval . Day ,
261
- "w" or "1w" or "week" => DateInterval . Week ,
262
- "M" or "1M" or "month" => DateInterval . Month ,
263
- "q" or "1q" or "quarter" => DateInterval . Quarter ,
264
- "y" or "1y" or "year" => DateInterval . Year ,
265
- _ => new Union < DateInterval , Time > ( proximity ) ,
258
+ "s" or "1s" or "second" => CalendarInterval . Second ,
259
+ "m" or "1m" or "minute" => CalendarInterval . Minute ,
260
+ "h" or "1h" or "hour" => CalendarInterval . Hour ,
261
+ "d" or "1d" or "day" => CalendarInterval . Day ,
262
+ "w" or "1w" or "week" => CalendarInterval . Week ,
263
+ "M" or "1M" or "month" => CalendarInterval . Month ,
264
+ "q" or "1q" or "quarter" => CalendarInterval . Quarter ,
265
+ "y" or "1y" or "year" => CalendarInterval . Year ,
266
+ _ => new Union < CalendarInterval , Duration > ( proximity ) ,
266
267
} ;
267
268
}
268
269
269
- private static Union < DateInterval , Time > GetInterval ( DateTime ? utcStart , DateTime ? utcEnd , int desiredDataPoints = 100 )
270
+ private static Union < CalendarInterval , Duration > GetInterval ( DateTime ? utcStart , DateTime ? utcEnd , int desiredDataPoints = 100 )
270
271
{
271
272
if ( ! utcStart . HasValue || ! utcEnd . HasValue || utcStart . Value == DateTime . MinValue )
272
- return DateInterval . Day ;
273
+ return CalendarInterval . Day ;
273
274
274
275
var totalTime = utcEnd . Value - utcStart . Value ;
275
276
var timePerBlock = TimeSpan . FromMinutes ( totalTime . TotalMinutes / desiredDataPoints ) ;
276
277
if ( timePerBlock . TotalDays > 1 )
277
278
{
278
279
timePerBlock = timePerBlock . Round ( TimeSpan . FromDays ( 1 ) ) ;
279
- return ( Time ) timePerBlock ;
280
+ return ( Duration ) timePerBlock ;
280
281
}
281
282
282
283
if ( timePerBlock . TotalHours > 1 )
283
284
{
284
285
timePerBlock = timePerBlock . Round ( TimeSpan . FromHours ( 1 ) ) ;
285
- return ( Time ) timePerBlock ;
286
+ return ( Duration ) timePerBlock ;
286
287
}
287
288
288
289
if ( timePerBlock . TotalMinutes > 1 )
289
290
{
290
291
timePerBlock = timePerBlock . Round ( TimeSpan . FromMinutes ( 1 ) ) ;
291
- return ( Time ) timePerBlock ;
292
+ return ( Duration ) timePerBlock ;
292
293
}
293
294
294
295
timePerBlock = timePerBlock . Round ( TimeSpan . FromSeconds ( 15 ) ) ;
295
296
if ( timePerBlock . TotalSeconds < 1 )
296
297
timePerBlock = TimeSpan . FromSeconds ( 15 ) ;
297
298
298
- return ( Time ) timePerBlock ;
299
+ return ( Duration ) timePerBlock ;
299
300
}
300
301
301
302
public static int ? GetProximityAsInt32 ( this IFieldQueryWithProximityAndBoostNode node )
0 commit comments