@@ -319,6 +319,130 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
319
319
}
320
320
}
321
321
322
+ // hide
323
+ #pragma warning disable 618
324
+ [ SkipVersion ( "<6.4.0" , "Missing added to Composite Aggregation Elasticsearch 6.4.0+" ) ]
325
+ public class CompositeAggregationMissingUsageTests : ProjectsOnlyAggregationUsageTestBase
326
+ {
327
+ public CompositeAggregationMissingUsageTests ( ReadOnlyCluster i , EndpointUsage usage ) : base ( i , usage ) { }
328
+
329
+ protected override object AggregationJson => new
330
+ {
331
+ my_buckets = new
332
+ {
333
+ composite = new
334
+ {
335
+ sources = new object [ ]
336
+ {
337
+ new
338
+ {
339
+ branches = new
340
+ {
341
+ terms = new
342
+ {
343
+ field = "branches.keyword" ,
344
+ order = "asc" ,
345
+ missing = "missing_branch"
346
+ }
347
+ }
348
+ } ,
349
+ }
350
+ } ,
351
+ aggs = new
352
+ {
353
+ project_tags = new
354
+ {
355
+ nested = new { path = "tags" } ,
356
+ aggs = new
357
+ {
358
+ tags = new { terms = new { field = "tags.name" } }
359
+ }
360
+ }
361
+ }
362
+ }
363
+ } ;
364
+
365
+ protected override Func < AggregationContainerDescriptor < Project > , IAggregationContainer > FluentAggs => a => a
366
+ . Composite ( "my_buckets" , date => date
367
+ . Sources ( s => s
368
+ . Terms ( "branches" , t => t
369
+ . Field ( f => f . Branches . Suffix ( "keyword" ) )
370
+
371
+ . Missing ( "missing_branch" )
372
+ . Order ( SortOrder . Ascending )
373
+ )
374
+ )
375
+ . Aggregations ( childAggs => childAggs
376
+ . Nested ( "project_tags" , n => n
377
+ . Path ( p => p . Tags )
378
+ . Aggregations ( nestedAggs => nestedAggs
379
+ . Terms ( "tags" , avg => avg . Field ( p => p . Tags . First ( ) . Name ) )
380
+ )
381
+ )
382
+ )
383
+ ) ;
384
+
385
+ protected override AggregationDictionary InitializerAggs =>
386
+ new CompositeAggregation ( "my_buckets" )
387
+ {
388
+ Sources = new List < ICompositeAggregationSource >
389
+ {
390
+ new TermsCompositeAggregationSource ( "branches" )
391
+ {
392
+ Field = Field < Project > ( f => f . Branches . Suffix ( "keyword" ) ) ,
393
+ Missing = "missing_branch" ,
394
+ Order = SortOrder . Ascending
395
+ }
396
+ } ,
397
+ Aggregations = new NestedAggregation ( "project_tags" )
398
+ {
399
+ Path = Field < Project > ( p => p . Tags ) ,
400
+ Aggregations = new TermsAggregation ( "tags" )
401
+ {
402
+ Field = Field < Project > ( p => p . Tags . First ( ) . Name )
403
+ }
404
+ }
405
+ } ;
406
+
407
+ protected override void ExpectResponse ( ISearchResponse < Project > response )
408
+ {
409
+ response . ShouldBeValid ( ) ;
410
+
411
+ var composite = response . Aggregations . Composite ( "my_buckets" ) ;
412
+ composite . Should ( ) . NotBeNull ( ) ;
413
+ composite . Buckets . Should ( ) . NotBeNullOrEmpty ( ) ;
414
+ composite . AfterKey . Should ( ) . NotBeNull ( ) ;
415
+
416
+ if ( TestConfiguration . Instance . InRange ( ">=6.3.0" ) )
417
+ composite . AfterKey . Should ( ) . HaveCount ( 1 ) . And . ContainKeys ( "branches" ) ;
418
+
419
+ var i = 0 ;
420
+ var seenMissingBranches = false ;
421
+ foreach ( var item in composite . Buckets )
422
+ {
423
+ var key = item . Key ;
424
+ key . Should ( ) . NotBeNull ( ) ;
425
+
426
+ key . TryGetValue ( "branches" , out string branches ) . Should ( ) . BeTrue ( "expected to find 'branches' in composite bucket" ) ;
427
+ branches . Should ( ) . NotBeNullOrEmpty ( ) ;
428
+ if ( branches == "missing_branch" )
429
+ {
430
+ seenMissingBranches = true ;
431
+ }
432
+
433
+ var nested = item . Nested ( "project_tags" ) ;
434
+ nested . Should ( ) . NotBeNull ( ) ;
435
+
436
+ var nestedTerms = nested . Terms ( "tags" ) ;
437
+ nestedTerms . Buckets . Count . Should ( ) . BeGreaterThan ( 0 ) ;
438
+ i ++ ;
439
+ }
440
+
441
+ seenMissingBranches . Should ( ) . BeTrue ( ) ;
442
+ }
443
+ }
444
+ #pragma warning restore 618
445
+
322
446
//hide
323
447
[ SkipVersion ( "<6.3.0" , "Date histogram source only supports format starting from Elasticsearch 6.3.0+" ) ]
324
448
public class DateFormatCompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
0 commit comments