11using System ;
2+ using System . Linq ;
23using FluentAssertions ;
34using Nest ;
45using Tests . Framework . Integration ;
@@ -20,6 +21,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
2021
2122 protected override object ExpectJson => new
2223 {
24+ size = 0 ,
2325 aggs = new
2426 {
2527 projects_started_per_month = new
@@ -39,13 +41,27 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
3941 } ,
4042 aggs = new
4143 {
42- project_tags = new { terms = new { field = "tags" } }
44+ project_tags = new
45+ {
46+ nested = new
47+ {
48+ path = "tags"
49+ } ,
50+ aggs = new
51+ {
52+ tags = new
53+ {
54+ terms = new { field = "tags.name" }
55+ }
56+ }
57+ }
4358 }
4459 }
4560 }
4661 } ;
4762
4863 protected override Func < SearchDescriptor < Project > , ISearchRequest > Fluent => s => s
64+ . Size ( 0 )
4965 . Aggregations ( aggs => aggs
5066 . DateHistogram ( "projects_started_per_month" , date => date
5167 . Field ( p => p . StartedOn )
@@ -55,14 +71,20 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
5571 . Order ( HistogramOrder . CountAscending )
5672 . Missing ( FixedDate )
5773 . Aggregations ( childAggs => childAggs
58- . Terms ( "project_tags" , avg => avg . Field ( p => p . Tags ) )
74+ . Nested ( "project_tags" , n => n
75+ . Path ( p => p . Tags )
76+ . Aggregations ( nestedAggs => nestedAggs
77+ . Terms ( "tags" , avg => avg . Field ( p => p . Tags . First ( ) . Name ) )
78+ )
79+ )
5980 )
6081 )
6182 ) ;
6283
6384 protected override SearchRequest < Project > Initializer =>
6485 new SearchRequest < Project >
6586 {
87+ Size = 0 ,
6688 Aggregations = new DateHistogramAggregation ( "projects_started_per_month" )
6789 {
6890 Field = Field < Project > ( p => p . StartedOn ) ,
@@ -75,8 +97,14 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
7597 } ,
7698 Order = HistogramOrder . CountAscending ,
7799 Missing = FixedDate ,
78- Aggregations =
79- new TermsAggregation ( "project_tags" ) { Field = Field < Project > ( p => p . Tags ) }
100+ Aggregations = new NestedAggregation ( "project_tags" )
101+ {
102+ Path = Field < Project > ( p => p . Tags ) ,
103+ Aggregations = new TermsAggregation ( "tags" )
104+ {
105+ Field = Field < Project > ( p => p . Tags . First ( ) . Name )
106+ }
107+ }
80108 }
81109 } ;
82110
@@ -96,6 +124,12 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
96124 {
97125 item . Date . Should ( ) . NotBe ( default ( DateTime ) ) ;
98126 item . DocCount . Should ( ) . BeGreaterThan ( 0 ) ;
127+
128+ var nested = item . Nested ( "project_tags" ) ;
129+ nested . Should ( ) . NotBeNull ( ) ;
130+
131+ var nestedTerms = nested . Terms ( "tags" ) ;
132+ nestedTerms . Buckets . Count . Should ( ) . BeGreaterThan ( 0 ) ;
99133 }
100134 }
101135 }
0 commit comments