use of org.elasticsearch.search.aggregations.pipeline.BucketSortPipelineAggregationBuilder in project starcoin-search by starcoinorg.
the class TokenService method tokenHolderList.
public Result<TokenStatistic> tokenHolderList(String network, int page, int count) {
SearchRequest searchRequest = new SearchRequest(getIndex(network, Constant.ADDRESS_INDEX));
int offset = (page - 1) * count;
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchAllQuery());
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("holders").field("type_tag.keyword").order(BucketOrder.aggregation("address_holders", false)).subAggregation(AggregationBuilders.count("address_holders").field("address.keyword")).subAggregation(new BucketSortPipelineAggregationBuilder("bucket_field", null).from(offset).size(count));
searchSourceBuilder.aggregation(aggregationBuilder);
searchSourceBuilder.trackTotalHits(true);
searchRequest.source(searchSourceBuilder);
searchSourceBuilder.timeout(new TimeValue(20, TimeUnit.SECONDS));
try {
return searchStatistic(client.search(searchRequest, RequestOptions.DEFAULT), StatisticType.AddressHolder);
} catch (IOException e) {
logger.error("get token stat error:", e);
return null;
}
}
use of org.elasticsearch.search.aggregations.pipeline.BucketSortPipelineAggregationBuilder in project starcoin-search by starcoinorg.
the class TokenService method tokenVolumeList.
public Result<TokenStatistic> tokenVolumeList(String network, int page, int count) {
SearchRequest searchRequest = new SearchRequest(getIndex(network, Constant.TRANSFER_JOURNAL_INDEX));
int offset = (page - 1) * count;
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
queryBuilder.must(QueryBuilders.rangeQuery("amount").gt(0)).must(QueryBuilders.rangeQuery("timestamp").gte("now/d-1d").lte("now/d"));
searchSourceBuilder.query(queryBuilder);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("token_stat").field("type_tag.keyword").order(BucketOrder.aggregation("amounts", false)).subAggregation(AggregationBuilders.sum("amounts").field("amount")).subAggregation(new BucketSortPipelineAggregationBuilder("bucket_field", null).from(offset).size(count));
searchSourceBuilder.aggregation(aggregationBuilder);
searchSourceBuilder.trackTotalHits(true);
searchRequest.source(searchSourceBuilder);
searchSourceBuilder.timeout(new TimeValue(20, TimeUnit.SECONDS));
try {
return searchStatistic(client.search(searchRequest, RequestOptions.DEFAULT), StatisticType.Volumes);
} catch (IOException e) {
logger.error("get token volume error:", e);
return null;
}
}
Aggregations