Search in sources :

Example 1 with BucketSortPipelineAggregationBuilder

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;
    }
}
Also used : BucketSortPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.BucketSortPipelineAggregationBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) IOException(java.io.IOException) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 2 with BucketSortPipelineAggregationBuilder

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;
    }
}
Also used : BucketSortPipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.BucketSortPipelineAggregationBuilder) SearchRequest(org.elasticsearch.action.search.SearchRequest) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IOException(java.io.IOException) TimeValue(org.elasticsearch.common.unit.TimeValue) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

IOException (java.io.IOException)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 TimeValue (org.elasticsearch.common.unit.TimeValue)2 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)2 BucketSortPipelineAggregationBuilder (org.elasticsearch.search.aggregations.pipeline.BucketSortPipelineAggregationBuilder)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1