我正在对负载数据使用Elasticsearch聚合,当传递偏移量计数时,响应结果正确显示,但术语聚合结果/存储桶始终仅显示10个结果。
Map<String, BucketStats> hourAggregations = new HashMap<>();
SearchResponse getResponse = client.prepareSearch( ElasticSearchConstants.INDEX ).setTypes( ElasticSearchConstants.TABLE)
.addAggregation( AggregationBuilders.terms( "name")
.field( "empId" )
.subAggregation( AggregationBuilders.stats( "stats" )
.setQuery( query )
.setFrom( 0 )
.setSize( ( offset + 1 ) * 10 )
.execute().actionGet();
Terms terms = getResponse.getAggregations().get("name");
for ( Terms.Bucket bucket : terms.getBuckets() )
{
//buckets showing only 10 results
}
答案 0 :(得分:1)
您需要为terms
聚合设置大小:
Map<String, BucketStats> hourAggregations = new HashMap<>();
SearchResponse getResponse = client.prepareSearch( ElasticSearchConstants.INDEX ).setTypes( ElasticSearchConstants.TABLE)
.addAggregation( AggregationBuilders.terms( "name")
.field( "empId" )
--> .size(100)
.subAggregation( AggregationBuilders.stats( "stats" )
.setQuery( query )
.setFrom( 0 )
.setSize( ( offset + 1 ) * 10 )
.execute().actionGet();
setSize()
调用仅影响hits
部分,即影响结果中设置的文档,而不影响汇总。按照我的看法,应该调用setSize(0)
,因为您只需要聚合值,而不是文档。