27
27
import org .elasticsearch .search .aggregations .metrics .TDigestState ;
28
28
import org .elasticsearch .test .ESSingleNodeTestCase ;
29
29
import org .elasticsearch .xpack .analytics .AnalyticsPlugin ;
30
+ import org .elasticsearch .xpack .analytics .boxplot .Boxplot ;
31
+ import org .elasticsearch .xpack .analytics .boxplot .BoxplotAggregationBuilder ;
30
32
import org .elasticsearch .xpack .core .LocalStateCompositeXPackPlugin ;
31
33
32
34
import java .util .ArrayList ;
@@ -131,8 +133,7 @@ public void testHDRHistogram() throws Exception {
131
133
}
132
134
}
133
135
134
- public void testTDigestHistogram () throws Exception {
135
-
136
+ private void setupTDigestHistogram (int compression ) throws Exception {
136
137
XContentBuilder xContentBuilder = XContentFactory .jsonBuilder ()
137
138
.startObject ()
138
139
.startObject ("_doc" )
@@ -170,8 +171,6 @@ public void testTDigestHistogram() throws Exception {
170
171
PutMappingRequest request2 = new PutMappingRequest ("pre_agg" ).source (xContentBuilder2 );
171
172
client ().admin ().indices ().putMapping (request2 ).actionGet ();
172
173
173
-
174
- int compression = TestUtil .nextInt (random (), 200 , 300 );
175
174
TDigestState histogram = new TDigestState (compression );
176
175
BulkRequest bulkRequest = new BulkRequest ();
177
176
@@ -218,6 +217,11 @@ public void testTDigestHistogram() throws Exception {
218
217
219
218
response = client ().prepareSearch ("pre_agg" ).get ();
220
219
assertEquals (numDocs / frq , response .getHits ().getTotalHits ().value );
220
+ }
221
+
222
+ public void testTDigestHistogram () throws Exception {
223
+ int compression = TestUtil .nextInt (random (), 200 , 300 );
224
+ setupTDigestHistogram (compression );
221
225
222
226
PercentilesAggregationBuilder builder =
223
227
AggregationBuilders .percentiles ("agg" ).field ("inner.data" ).method (PercentilesMethod .TDIGEST )
@@ -236,6 +240,31 @@ public void testTDigestHistogram() throws Exception {
236
240
}
237
241
}
238
242
243
+ public void testBoxplotHistogram () throws Exception {
244
+ int compression = TestUtil .nextInt (random (), 200 , 300 );
245
+ setupTDigestHistogram (compression );
246
+ BoxplotAggregationBuilder bpBuilder = new BoxplotAggregationBuilder ("agg" ).field ("inner.data" ).compression (compression );
247
+
248
+ SearchResponse bpResponseRaw = client ().prepareSearch ("raw" ).addAggregation (bpBuilder ).get ();
249
+ SearchResponse bpResponsePreAgg = client ().prepareSearch ("pre_agg" ).addAggregation (bpBuilder ).get ();
250
+ SearchResponse bpResponseBoth = client ().prepareSearch ("raw" , "pre_agg" ).addAggregation (bpBuilder ).get ();
251
+
252
+ Boxplot bpRaw = bpResponseRaw .getAggregations ().get ("agg" );
253
+ Boxplot bpPreAgg = bpResponsePreAgg .getAggregations ().get ("agg" );
254
+ Boxplot bpBoth = bpResponseBoth .getAggregations ().get ("agg" );
255
+ assertEquals (bpRaw .getMax (), bpPreAgg .getMax (), 0.0 );
256
+ assertEquals (bpRaw .getMax (), bpBoth .getMax (), 0.0 );
257
+ assertEquals (bpRaw .getMin (), bpPreAgg .getMin (), 0.0 );
258
+ assertEquals (bpRaw .getMin (), bpBoth .getMin (), 0.0 );
259
+
260
+ assertEquals (bpRaw .getQ1 (), bpPreAgg .getQ1 (), 1.0 );
261
+ assertEquals (bpRaw .getQ1 (), bpBoth .getQ1 (), 1.0 );
262
+ assertEquals (bpRaw .getQ2 (), bpPreAgg .getQ2 (), 1.0 );
263
+ assertEquals (bpRaw .getQ2 (), bpBoth .getQ2 (), 1.0 );
264
+ assertEquals (bpRaw .getQ3 (), bpPreAgg .getQ3 (), 1.0 );
265
+ assertEquals (bpRaw .getQ3 (), bpBoth .getQ3 (), 1.0 );
266
+ }
267
+
239
268
@ Override
240
269
protected Collection <Class <? extends Plugin >> getPlugins () {
241
270
List <Class <? extends Plugin >> plugins = new ArrayList <>(super .getPlugins ());
0 commit comments