Search in sources :

Example 1 with BucketSortPipelineAggregationBuilder

use of org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregationBuilder in project pancm_project by xuwujing.

the class EsAggregationSearchTest2 method test.

private static void test() throws IOException {
    // TermsAggregationBuilder termsBuilder = AggregationBuilders.terms("ecid").field("ecid").size(99999);
    // List<FieldSortBuilder> fieldSorts=new ArrayList<>();
    // fieldSorts.add(new FieldSortBuilder("sum_field").order(SortOrder.DESC));
    // termsBuilder.subAggregation(new BucketSortPipelineAggregationBuilder("bucket_field", fieldSorts).from(6000).size(10));
    // 
    AggregationBuilder aggregation = AggregationBuilders.terms("ecid").field("ecid");
    List<FieldSortBuilder> fieldSorts = new ArrayList<>();
    fieldSorts.add(new FieldSortBuilder("id_").order(SortOrder.DESC));
    aggregation.subAggregation(new BucketSortPipelineAggregationBuilder("id", fieldSorts).from(0).size(10));
    SearchResponse searchResponse = search(aggregation);
    // 获取聚合结果
    Aggregations aggregations = searchResponse.getAggregations();
    Map<String, Object> map = new HashMap<>();
    List<Map<String, Object>> list = new ArrayList<>();
    agg(map, list, aggregations);
    logger.info("聚合查询结果:" + list);
    logger.info("------------------------------------");
}
Also used : BucketSortPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregationBuilder) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) BucketSortPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregationBuilder) HashMap(java.util.HashMap) Aggregations(org.elasticsearch.search.aggregations.Aggregations) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)1 Aggregations (org.elasticsearch.search.aggregations.Aggregations)1 BucketSortPipelineAggregationBuilder (org.elasticsearch.search.aggregations.pipeline.bucketsort.BucketSortPipelineAggregationBuilder)1 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)1