1
1
using System ;
2
+ using System . Linq ;
2
3
using FluentAssertions ;
3
4
using Nest ;
4
5
using Tests . Framework . Integration ;
@@ -20,6 +21,7 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
20
21
21
22
protected override object ExpectJson => new
22
23
{
24
+ size = 0 ,
23
25
aggs = new
24
26
{
25
27
projects_started_per_month = new
@@ -39,13 +41,27 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
39
41
} ,
40
42
aggs = new
41
43
{
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
+ }
43
58
}
44
59
}
45
60
}
46
61
} ;
47
62
48
63
protected override Func < SearchDescriptor < Project > , ISearchRequest > Fluent => s => s
64
+ . Size ( 0 )
49
65
. Aggregations ( aggs => aggs
50
66
. DateHistogram ( "projects_started_per_month" , date => date
51
67
. Field ( p => p . StartedOn )
@@ -55,14 +71,20 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
55
71
. Order ( HistogramOrder . CountAscending )
56
72
. Missing ( FixedDate )
57
73
. 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
+ )
59
80
)
60
81
)
61
82
) ;
62
83
63
84
protected override SearchRequest < Project > Initializer =>
64
85
new SearchRequest < Project >
65
86
{
87
+ Size = 0 ,
66
88
Aggregations = new DateHistogramAggregation ( "projects_started_per_month" )
67
89
{
68
90
Field = Field < Project > ( p => p . StartedOn ) ,
@@ -75,8 +97,14 @@ public DateHistogramAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage
75
97
} ,
76
98
Order = HistogramOrder . CountAscending ,
77
99
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
+ }
80
108
}
81
109
} ;
82
110
@@ -96,6 +124,12 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
96
124
{
97
125
item . Date . Should ( ) . NotBe ( default ( DateTime ) ) ;
98
126
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 ) ;
99
133
}
100
134
}
101
135
}
0 commit comments