I am doing aggregation like this:
{
"size":0,
"aggs":
{
"my_aggs":
{
"terms":
{
"field":"my_field"
}
}
}
}
I want to get only the aggregation result. So when I set size=0
like below, it gives error-later learned this is for how many results I want(aggregations). So, how can I achieve this to get only the aggregation results(no hits result docs)
AbstractAggregationBuilder aggregationBuilder = AggregationBuilders
.terms("my_aggs")
.field("my_field")
.size(0) //how to set size for my purpose?
.order(BucketOrder.key(true));
Moreover, If I get thousands of aggregation results, does this query return all of them? or apply to its default 10 size? If not, how do know how many should I set size of aggregation result.
Edit I am adding my aggregation like this:
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withIndices(indexName)
.withTypes(typeName)
.withQuery(boolQueryBuilder)
.addAggregation(aggregationBuilder)
.build();
Please help.