diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java index 9c9c5425f0006..53a29060f75f1 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java @@ -44,6 +44,7 @@ import org.elasticsearch.index.query.MatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.ScriptQueryBuilder; +import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.join.aggregations.Children; import org.elasticsearch.join.aggregations.ChildrenAggregationBuilder; @@ -59,6 +60,9 @@ import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.bucket.range.Range; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.significant.SignificantTerms; +import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.matrix.stats.MatrixStats; @@ -267,6 +271,33 @@ public void testSearchWithTermsAgg() throws IOException { assertEquals(2, type2.getDocCount()); assertEquals(0, type2.getAggregations().asList().size()); } + + public void testSearchWithSignificantTermsAgg() throws IOException { + SearchRequest searchRequest = new SearchRequest(); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + searchSourceBuilder.query(new MatchQueryBuilder("num","50")); + searchSourceBuilder.aggregation(new SignificantTermsAggregationBuilder("agg1", ValueType.STRING) + .field("type.keyword") + .minDocCount(1) + .significanceHeuristic(new PercentageScore())); + searchSourceBuilder.size(0); + searchRequest.source(searchSourceBuilder); + SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync); + assertSearchHeader(searchResponse); + assertNull(searchResponse.getSuggest()); + assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); + assertEquals(0, searchResponse.getHits().getHits().length); + assertEquals(0f, searchResponse.getHits().getMaxScore(), 0f); + SignificantTerms significantTermsAgg = searchResponse.getAggregations().get("agg1"); + assertEquals("agg1", significantTermsAgg.getName()); + assertEquals(1, significantTermsAgg.getBuckets().size()); + SignificantTerms.Bucket type1 = significantTermsAgg.getBucketByKey("type1"); + assertEquals(1, type1.getDocCount()); + assertEquals(1, type1.getSubsetDf()); + assertEquals(1, type1.getSubsetSize()); + assertEquals(3, type1.getSupersetDf()); + assertEquals(1d/3d, type1.getSignificanceScore(), 0d); + } public void testSearchWithRangeAgg() throws IOException { { diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/ParsedSignificantTerms.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/ParsedSignificantTerms.java index 1b4739c184d5e..26c4ec420d080 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/ParsedSignificantTerms.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/ParsedSignificantTerms.java @@ -175,7 +175,7 @@ static B parseSignificantTermsBucketXContent(final XCon bucket.subsetDf = value; bucket.setDocCount(value); } else if (InternalSignificantTerms.SCORE.equals(currentFieldName)) { - bucket.score = parser.longValue(); + bucket.score = parser.doubleValue(); } else if (InternalSignificantTerms.BG_COUNT.equals(currentFieldName)) { bucket.supersetDf = parser.longValue(); }