org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder.
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: SearchServiceImpl.java From dk-fitting with Apache License 2.0 | 5 votes |
/** * 聚合统计, * @param hostIp ES集群的ip地址 * @param clusterName ES集群集群名称 * @param indexName ES集群的索引名称,可使用多个索引 indexName="test2,test1,test"; * @param typeName 索引类型,可多个 typeName="doc,pdf,test"; * @param port ES集群的端口号 * @param aggFdName 需要统计的字段 * @param aggType 记录偏移 , null-默认为10 * @return * @throws TException */ @Override public Map<String, String> StatsAggregation(String hostIp, int port, String clusterName, String indexName, String typeName, String aggFdName, String aggType) throws TException { Client client=null; try { client = ESUtils.getClient( hostIp, port, clusterName ); } catch (Exception e) { e.printStackTrace(); } ExtendedStatsAggregationBuilder aggregationBuilder = AggregationBuilders.extendedStats( "agg" ).field( aggFdName ); SearchResponse response = client.prepareSearch( indexName ).addAggregation( aggregationBuilder ).get(); ExtendedStats agg = response.getAggregations().get( "agg" ); Map<String,String> map=new LinkedHashMap<>( ); map.put("avg", agg.getAvgAsString() ); map.put("count", String.valueOf( agg.getCount() ) ); map.put("sum", agg.getSumAsString() ); map.put("max", agg.getMaxAsString() ); map.put("min", agg.getMinAsString() ); //以字符串形式收集的值的标准偏差。 map.put( "StdDeviation",agg.getStdDeviationAsString() ); //平方和 map.put( "SumOfSquares" ,agg.getSumOfSquaresAsString()); //方差 map.put( "Variance",agg.getStdDeviationAsString() ); System.out.println( "stats avg"+agg.getAvgAsString()+"count"+agg.getCount()+"max"+agg.getMaxAsString()+"min"+agg.getMinAsString()+"sum"+agg.getSumAsString() ); return map; }
Example #2
Source File: AggregationHelper.java From fast-elasticsearch-query-builder with Apache License 2.0 | 5 votes |
private static void setExtendedStatsAggregation(SearchSourceBuilder searchSource, ExtendedStatsAggregation aggregation, Boolean value) { if (!value) { return; } ExtendedStatsAggregationBuilder extendedStatsAggregation = new ExtendedStatsAggregationBuilder(aggregation.name()).field(aggregation.field()); searchSource.aggregation(extendedStatsAggregation); }
Example #3
Source File: ElasticsearchSearchQueryBase.java From vertexium with Apache License 2.0 | 5 votes |
protected List<AbstractAggregationBuilder> getElasticsearchStatisticsAggregations(StatisticsAggregation agg) { List<AbstractAggregationBuilder> aggs = new ArrayList<>(); for (String propertyName : getPropertyNames(agg.getFieldName())) { String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName); String aggName = createAggregationName(agg.getAggregationName(), visibilityHash); ExtendedStatsAggregationBuilder statsAgg = AggregationBuilders.extendedStats(aggName); statsAgg.field(propertyName); aggs.add(statsAgg); } return aggs; }