weedsssssss
weedsssssss
2019-11-06 15:10
采纳率: 0%
浏览 346

怎么把es聚合查询的结果写到接口里呢?

public Page<Item> testAgg(){
    NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder();

    queryBuilder.withSourceFilter(new FetchSourceFilter(new String[]{""}, null));

    queryBuilder.addAggregation(
            AggregationBuilders.terms("brands").field("brand.keyword"));

    AggregatedPage<Item> aggPage = (AggregatedPage<Item>) this.itemRepository.search(queryBuilder.build());

    StringTerms agg = (StringTerms) aggPage.getAggregation("brands");

    List<StringTerms.Bucket> buckets = agg.getBuckets();

    for (StringTerms.Bucket bucket : buckets) {

        System.out.println(bucket.getKeyAsString());

        System.out.println(bucket.getDocCount());
    }
return  
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • sudadaipeng1
    pdai 2019-11-06 15:19

    controller提供接口,查询结果序列化为json

    点赞 评论

相关推荐