Skip to content

Commit c714d29

Browse files
committed
terms aggregation - min_doc_count support NLPchina#178
1 parent 717c898 commit c714d29

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/main/java/org/nlpcn/es4sql/query/AggregationQueryAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public SqlElasticSearchRequestBuilder explain() throws SqlParseException {
5656
Field field = groupBy.get(0);
5757
lastAgg = aggMaker.makeGroupAgg(field);
5858

59-
if (lastAgg != null && lastAgg instanceof TermsBuilder) {
59+
if (lastAgg != null && lastAgg instanceof TermsBuilder && !(field instanceof MethodField )) {
60+
6061
((TermsBuilder) lastAgg).size(select.getRowCount());
6162
}
6263

src/main/java/org/nlpcn/es4sql/query/maker/AggMaker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ private AggregationBuilder<?> termsAgg(MethodField field) throws SqlParseExcepti
229229
case "shard_size":
230230
terms.shardSize(Integer.parseInt(value));
231231
break;
232+
case "min_doc_count":
233+
terms.minDocCount(Integer.parseInt(value));
234+
break;
232235
case "alias":
233236
case "nested":
234237
case "reverse_nested":

src/test/java/org/nlpcn/es4sql/AggregationTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ public void multipleGroupBysWithSize() throws Exception {
254254

255255
}
256256

257+
@Test
258+
public void termsWithSize() throws Exception {
259+
260+
Map<String, Set<Integer>> buckets = new HashMap<>();
261+
262+
Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY terms('alias'='ageAgg','field'='age','size'=3)", TEST_INDEX));
263+
Terms gender = result.get("ageAgg");
264+
Assert.assertEquals(3,gender.getBuckets().size());
265+
266+
}
257267

258268

259269
@Test
@@ -466,7 +476,7 @@ public void geoHashGrid() throws SQLFeatureNotSupportedException, SqlParseExcept
466476
InternalGeoHashGrid grid = result.get("geohash_grid(field=center,precision=5)");
467477
Collection<GeoHashGrid.Bucket> buckets = grid.getBuckets();
468478
for (GeoHashGrid.Bucket bucket : buckets) {
469-
Assert.assertTrue(bucket.getKey().toString().equals("[4.98779296875, 105.00732421875]") || bucket.getKey().toString().equals("[0.50537109375, 100.48095703125]") );
479+
Assert.assertTrue(bucket.getKey().toString().equals("[4.9658203125, 104.9853515625]") || bucket.getKey().toString().equals("[0.4833984375, 100.458984375]") );
470480
Assert.assertEquals(1,bucket.getDocCount());
471481
}
472482
}

0 commit comments

Comments
 (0)