Java Code Examples for org.elasticsearch.search.aggregations.Aggregations#asMap()
The following examples show how to use
org.elasticsearch.search.aggregations.Aggregations#asMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxMinAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ // MaxAggregationBuilder aggregationBuilder = AggregationBuilders.max("utm").field("utm"); MinAggregationBuilder aggregationBuilder = AggregationBuilders.min("utm").field("utm"); SearchRequest searchRequest = new SearchRequest("serverlog_20180715");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.aggregation(aggregationBuilder); searchSourceBuilder.size(0);//设置不需要文档数据,只需要返回聚合结果 searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); //统计结果 Aggregations aggregations = searchResponse.getAggregations(); Map<String, Aggregation> aggregationMap = aggregations.asMap(); for(Map.Entry<String,Aggregation> each: aggregationMap.entrySet()){ // System.out.println(((ParsedMax)(each.getValue())).getValue()); System.out.println(((ParsedMin)(each.getValue())).getValue()); } }finally{ HighLevelClient.close(); } }
Example 2
Source File: CountAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ QueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("cmd", "get_fee_transfer_content_data"); ValueCountAggregationBuilder aggregationBuilder = AggregationBuilders.count("cmd_count").field("cmd"); SearchRequest searchRequest = new SearchRequest("serverlog_20180715");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(matchQueryBuilder); searchSourceBuilder.aggregation(aggregationBuilder); searchSourceBuilder.size(0);//不返回具体业务数据,只需要聚合结果 searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); //统计结果 Aggregations aggregations = searchResponse.getAggregations(); Map<String, Aggregation> aggregationMap = aggregations.asMap(); for(Map.Entry<String,Aggregation> each: aggregationMap.entrySet()){ System.out.println(((ParsedValueCount)(each.getValue())).getValue()); } }finally{ HighLevelClient.close(); } }
Example 3
Source File: SumAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ // QueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("cmd", "weather_hourforcast"); SumAggregationBuilder aggregationBuilder = AggregationBuilders.sum("utm").field("utm"); SearchRequest searchRequest = new SearchRequest("serverlog_20180715");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // searchSourceBuilder.query(matchQueryBuilder); searchSourceBuilder.aggregation(aggregationBuilder); searchSourceBuilder.size(0); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); //统计结果 Aggregations aggregations = searchResponse.getAggregations(); Map<String, Aggregation> aggregationMap = aggregations.asMap(); for(Map.Entry<String,Aggregation> each: aggregationMap.entrySet()){ System.out.println(((ParsedSum)(each.getValue())).getValue()); } }finally{ HighLevelClient.close(); } }
Example 4
Source File: AvgAggregationMain.java From elasticsearch-pool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { RestHighLevelClient client = HighLevelClient.getInstance(); try{ AvgAggregationBuilder aggregationBuilder = AggregationBuilders.avg("utm").field("utm").missing(0); SearchRequest searchRequest = new SearchRequest("serverlog_20180715");//限定index searchRequest.types("log");//限定type SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.aggregation(aggregationBuilder); searchSourceBuilder.size(0); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = client.search(searchRequest); System.out.println(searchResponse); //统计结果 Aggregations aggregations = searchResponse.getAggregations(); Map<String, Aggregation> aggregationMap = aggregations.asMap(); for(Map.Entry<String,Aggregation> each: aggregationMap.entrySet()){ System.out.println(((ParsedAvg)(each.getValue())).getValue()); } }finally{ HighLevelClient.close(); } }
Example 5
Source File: ElasticSearchTypeImpl.java From core-ng-project with Apache License 2.0 | 5 votes |
private SearchResponse<T> searchResponse(org.elasticsearch.action.search.SearchResponse response) { SearchHit[] hits = response.getHits().getHits(); List<T> items = new ArrayList<>(hits.length); for (SearchHit hit : hits) { items.add(mapper.fromJSON(BytesReference.toBytes(hit.getSourceRef()))); } Aggregations aggregationResponse = response.getAggregations(); Map<String, Aggregation> aggregations = aggregationResponse == null ? Map.of() : aggregationResponse.asMap(); TotalHits totalHits = response.getHits().getTotalHits(); long total = totalHits == null ? -1 : totalHits.value; return new SearchResponse<>(items, total, aggregations); }