@@ -32,7 +32,7 @@ namespace Tests.Aggregations.Bucket.Composite
3232 *
3333 * Be sure to read the Elasticsearch documentation on {ref_current}/search-aggregations-bucket-composite-aggregation.html[Composite Aggregation].
3434 */
35- [ SkipVersion ( "<6.1.0" , "Composite Aggregation is only available in Elasticsearch 6.1.0+" ) ]
35+ // [SkipVersion("<6.1.0", "Composite Aggregation is only available in Elasticsearch 6.1.0+")]
3636 public class CompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
3737 {
3838 public CompositeAggregationUsageTests ( ReadOnlyCluster i , EndpointUsage usage ) : base ( i , usage ) { }
@@ -196,9 +196,123 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
196196 }
197197 }
198198
199+ public class CompositeAggregationMissingBucketUsageTests : ProjectsOnlyAggregationUsageTestBase
200+ {
201+ public CompositeAggregationMissingBucketUsageTests ( ReadOnlyCluster i , EndpointUsage usage ) : base ( i , usage ) { }
202+
203+ protected override object AggregationJson => new
204+ {
205+ my_buckets = new
206+ {
207+ composite = new
208+ {
209+ sources = new object [ ]
210+ {
211+ new
212+ {
213+ branches = new
214+ {
215+ terms = new
216+ {
217+ field = "branches.keyword" ,
218+ order = "asc" ,
219+ missing_bucket = true
220+ }
221+ }
222+ } ,
223+ }
224+ } ,
225+ aggs = new
226+ {
227+ project_tags = new
228+ {
229+ nested = new { path = "tags" } ,
230+ aggs = new
231+ {
232+ tags = new { terms = new { field = "tags.name" } }
233+ }
234+ }
235+ }
236+ }
237+ } ;
238+
239+ protected override Func < AggregationContainerDescriptor < Project > , IAggregationContainer > FluentAggs => a => a
240+ . Composite ( "my_buckets" , date => date
241+ . Sources ( s => s
242+ . Terms ( "branches" , t => t
243+ . Field ( f => f . Branches . Suffix ( "keyword" ) )
244+ . MissingBucket ( )
245+ . Order ( SortOrder . Ascending )
246+ )
247+ )
248+ . Aggregations ( childAggs => childAggs
249+ . Nested ( "project_tags" , n => n
250+ . Path ( p => p . Tags )
251+ . Aggregations ( nestedAggs => nestedAggs
252+ . Terms ( "tags" , avg => avg . Field ( p => p . Tags . First ( ) . Name ) )
253+ )
254+ )
255+ )
256+ ) ;
257+
258+ protected override AggregationDictionary InitializerAggs =>
259+ new CompositeAggregation ( "my_buckets" )
260+ {
261+ Sources = new List < ICompositeAggregationSource >
262+ {
263+ new TermsCompositeAggregationSource ( "branches" )
264+ {
265+ Field = Infer . Field < Project > ( f => f . Branches . Suffix ( "keyword" ) ) ,
266+ MissingBucket = true ,
267+ Order = SortOrder . Ascending
268+ }
269+ } ,
270+ Aggregations = new NestedAggregation ( "project_tags" )
271+ {
272+ Path = Field < Project > ( p => p . Tags ) ,
273+ Aggregations = new TermsAggregation ( "tags" )
274+ {
275+ Field = Field < Project > ( p => p . Tags . First ( ) . Name )
276+ }
277+ }
278+ } ;
279+
280+ /**==== Handling Responses
281+ * Each Composite aggregation bucket key is an `CompositeKey`, a specialized
282+ * `IReadOnlyDictionary<string, object>` type with methods to convert values to supported types
283+ */
284+ protected override void ExpectResponse ( ISearchResponse < Project > response )
285+ {
286+ response . ShouldBeValid ( ) ;
287+
288+ var composite = response . Aggregations . Composite ( "my_buckets" ) ;
289+ composite . Should ( ) . NotBeNull ( ) ;
290+ composite . Buckets . Should ( ) . NotBeNullOrEmpty ( ) ;
291+ composite . AfterKey . Should ( ) . NotBeNull ( ) ;
292+ if ( TestConfiguration . Instance . InRange ( ">=6.3.0" ) )
293+ composite . AfterKey . Should ( ) . HaveCount ( 1 ) . And . ContainKeys ( "branches" ) ;
294+ var i = 0 ;
295+ foreach ( var item in composite . Buckets )
296+ {
297+ var key = item . Key ;
298+ key . Should ( ) . NotBeNull ( ) ;
299+
300+ key . TryGetValue ( "branches" , out string branches ) . Should ( ) . BeTrue ( "expected to find 'branches' in composite bucket" ) ;
301+ if ( i == 0 ) branches . Should ( ) . BeNull ( "First key should be null as we expect to have some projects with no branches" ) ;
302+ else branches . Should ( ) . NotBeNullOrEmpty ( ) ;
303+
304+ var nested = item . Nested ( "project_tags" ) ;
305+ nested . Should ( ) . NotBeNull ( ) ;
306+
307+ var nestedTerms = nested . Terms ( "tags" ) ;
308+ nestedTerms . Buckets . Count . Should ( ) . BeGreaterThan ( 0 ) ;
309+ i ++ ;
310+ }
311+ }
312+ }
199313
200314 //hide
201- [ SkipVersion ( "<6.3.0" , "Date histogram source only supports format starting from Elasticsearch 6.3.0+" ) ]
315+ // [SkipVersion("<6.3.0", "Date histogram source only supports format starting from Elasticsearch 6.3.0+")]
202316 public class DateFormatCompositeAggregationUsageTests : ProjectsOnlyAggregationUsageTestBase
203317 {
204318 public DateFormatCompositeAggregationUsageTests ( ReadOnlyCluster i , EndpointUsage usage ) : base ( i , usage ) { }
0 commit comments