@@ -54,4 +54,71 @@ protected override void ExpectResponse(SearchResponse<Project> response)
54
54
commitStats . StdDeviationBounds . Lower . Should ( ) . NotBe ( 0 ) ;
55
55
}
56
56
}
57
+
58
+ /// <summary>
59
+ /// Asserts that stats sum is 0 (and not null) when matching document count is 0
60
+ /// </summary>
61
+ // hide
62
+ public class ExtendedStatsAggregationUsageDocCountZeroTests : AggregationUsageTestBase
63
+ {
64
+ public ExtendedStatsAggregationUsageDocCountZeroTests ( ReadOnlyCluster i , EndpointUsage usage ) : base ( i , usage ) { }
65
+
66
+ // a query that no docs will match
67
+ protected override QueryContainer QueryScope => base . QueryScope &&
68
+ new TermQuery { Field = Field < Project > ( f => f . Branches ) , Value = "non-existent branch name" } ;
69
+
70
+ protected override object QueryScopeJson { get ; } = new
71
+ {
72
+ @bool = new
73
+ {
74
+ must = new object [ ]
75
+ {
76
+ new { term = new { type = new { value = Project . TypeName } } } ,
77
+ new { term = new { branches = new { value = "non-existent branch name" } } } ,
78
+ }
79
+ }
80
+
81
+ } ;
82
+
83
+ protected override object AggregationJson => new
84
+ {
85
+ commit_stats = new
86
+ {
87
+ extended_stats = new
88
+ {
89
+ field = "numberOfCommits" ,
90
+ sigma = 1d
91
+ }
92
+ }
93
+ } ;
94
+
95
+ protected override Func < AggregationContainerDescriptor < Project > , IAggregationContainer > FluentAggs => a => a
96
+ . ExtendedStats ( "commit_stats" , es => es
97
+ . Field ( p => p . NumberOfCommits )
98
+ . Sigma ( 1 )
99
+ ) ;
100
+
101
+ protected override AggregationDictionary InitializerAggs =>
102
+ new ExtendedStatsAggregation ( "commit_stats" , Field < Project > ( p => p . NumberOfCommits ) )
103
+ {
104
+ Sigma = 1
105
+ } ;
106
+
107
+ protected override void ExpectResponse ( SearchResponse < Project > response )
108
+ {
109
+ response . ShouldBeValid ( ) ;
110
+ var commitStats = response . Aggregations . ExtendedStats ( "commit_stats" ) ;
111
+ commitStats . Count . Should ( ) . Be ( 0 ) ;
112
+ commitStats . Sum . Should ( ) . Be ( 0 ) ;
113
+ commitStats . Should ( ) . NotBeNull ( ) ;
114
+ commitStats . Average . Should ( ) . BeNull ( ) ;
115
+ commitStats . Max . Should ( ) . BeNull ( ) ;
116
+ commitStats . Min . Should ( ) . BeNull ( ) ;
117
+ commitStats . SumOfSquares . Should ( ) . BeNull ( ) ;
118
+ commitStats . Variance . Should ( ) . BeNull ( ) ;
119
+ commitStats . StdDeviation . Should ( ) . BeNull ( ) ;
120
+ commitStats . StdDeviationBounds . Upper . Should ( ) . BeNull ( ) ;
121
+ commitStats . StdDeviationBounds . Lower . Should ( ) . BeNull ( ) ;
122
+ }
123
+ }
57
124
}
0 commit comments