|
59 | 59 | import org.elasticsearch.search.aggregations.BucketOrder;
|
60 | 60 | import org.elasticsearch.search.aggregations.bucket.range.Range;
|
61 | 61 | import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
|
| 62 | +import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; |
| 63 | +import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder; |
| 64 | +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore; |
62 | 65 | import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
63 | 66 | import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
64 | 67 | import org.elasticsearch.search.aggregations.matrix.stats.MatrixStats;
|
@@ -267,6 +270,33 @@ public void testSearchWithTermsAgg() throws IOException {
|
267 | 270 | assertEquals(2, type2.getDocCount());
|
268 | 271 | assertEquals(0, type2.getAggregations().asList().size());
|
269 | 272 | }
|
| 273 | + |
| 274 | + public void testSearchWithSignificantTermsAgg() throws IOException { |
| 275 | + SearchRequest searchRequest = new SearchRequest(); |
| 276 | + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); |
| 277 | + searchSourceBuilder.query(new MatchQueryBuilder("num","50")); |
| 278 | + searchSourceBuilder.aggregation(new SignificantTermsAggregationBuilder("agg1", ValueType.STRING) |
| 279 | + .field("type.keyword") |
| 280 | + .minDocCount(1) |
| 281 | + .significanceHeuristic(new PercentageScore())); |
| 282 | + searchSourceBuilder.size(0); |
| 283 | + searchRequest.source(searchSourceBuilder); |
| 284 | + SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync); |
| 285 | + assertSearchHeader(searchResponse); |
| 286 | + assertNull(searchResponse.getSuggest()); |
| 287 | + assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); |
| 288 | + assertEquals(0, searchResponse.getHits().getHits().length); |
| 289 | + assertEquals(0f, searchResponse.getHits().getMaxScore(), 0f); |
| 290 | + SignificantTerms significantTermsAgg = searchResponse.getAggregations().get("agg1"); |
| 291 | + assertEquals("agg1", significantTermsAgg.getName()); |
| 292 | + assertEquals(1, significantTermsAgg.getBuckets().size()); |
| 293 | + SignificantTerms.Bucket type1 = significantTermsAgg.getBucketByKey("type1"); |
| 294 | + assertEquals(1, type1.getDocCount()); |
| 295 | + assertEquals(1, type1.getSubsetDf()); |
| 296 | + assertEquals(1, type1.getSubsetSize()); |
| 297 | + assertEquals(3, type1.getSupersetDf()); |
| 298 | + assertEquals(1d/3d, type1.getSignificanceScore(), 0d); |
| 299 | + } |
270 | 300 |
|
271 | 301 | public void testSearchWithRangeAgg() throws IOException {
|
272 | 302 | {
|
|
0 commit comments