org.elasticsearch.search.aggregations.metrics.percentiles.Percentile Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.metrics.percentiles.Percentile.
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 |
/** * *对指定字段(脚本)的值按从小到大累计每个值对应的文档数的占比(占所有命中文档数的百分比),返回指定占比比例对应的值。 * 默认返回[ 1, 5, 25, 50, 75, 95, 99 ]分位上的值。如下中间的结果,可以理解为:占比为50%的文档的age值 <= 31, * 或反过来:age<=31的文档数占总命中文档数的50% * 也可以自己指定分位值,如 10,50,90. * @param hostIp ES集群的ip地址 * @param port ES集群的端口号 * @param clusterName ES集群名称 * @param indexName ES集群的索引名称,可使用多个索引 indexName="test2,test1,test"; * @param typeName 索引类型,可多个 typeName="doc,pdf,test"; * @param aggFdName 字段名称 * @param percentiles 自定义百分比分位数,比如10,50,90 之间以","分隔 * @return * @throws TException */ @Override public Map<String, String> PercentilesAggregation(String hostIp, int port, String clusterName, String indexName, String typeName, String aggFdName, String percentiles) throws TException { Client client=null; try { client = ESUtils.getClient( hostIp, port, clusterName ); } catch (Exception e) { e.printStackTrace(); } PercentilesAggregationBuilder aggregation=null; if(percentiles==null&&percentiles.equals( "" )) { aggregation = AggregationBuilders.percentiles( aggFdName + "_percentiles" ).field( aggFdName ); }else { double[] parseDouble=new double[10]; if(percentiles.contains( "," )){ String[] split = percentiles.split( "," ); for (int i = 0; i <split.length ; i++) { parseDouble[i] = Double.parseDouble( split[i] ); } }else { parseDouble=new double[]{Double.parseDouble( percentiles )}; } aggregation = AggregationBuilders.percentiles( aggFdName + "_percentiles" ).field( aggFdName ).percentiles( parseDouble ); } SearchResponse sr = client.prepareSearch(indexName) .addAggregation(aggregation) .get(); Percentiles percentiles1 = sr.getAggregations().get( aggFdName+"_percentiles" ); Map map=new LinkedHashMap( ); for (Percentile percentile:percentiles1) { System.out.println("global " + percentile.getPercent() + " count:" + percentile.getValue()); map.put( String.valueOf(percentile.getPercent()+"%" ),String.valueOf(aggFdName+"="+ percentile.getValue()) ); } return map; }
Example #2
Source File: Utils.java From foxtrot with Apache License 2.0 | 5 votes |
public static Map<Number, Number> createPercentilesResponse(Percentiles internalPercentiles) { Map<Number, Number> percentiles = Maps.newHashMap(); for (Percentile percentile : internalPercentiles) { percentiles.put(percentile.getPercent(), percentile.getValue()); } return percentiles; }
Example #3
Source File: InternalHDRPercentileRanks.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<Percentile> iterator() { return new Iter(keys, state); }
Example #4
Source File: InternalHDRPercentiles.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<Percentile> iterator() { return new Iter(keys, state); }
Example #5
Source File: InternalTDigestPercentileRanks.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<Percentile> iterator() { return new Iter(keys, state); }
Example #6
Source File: InternalTDigestPercentiles.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<Percentile> iterator() { return new Iter(keys, state); }
Example #7
Source File: InternalPercentilesBucket.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public Iterator<Percentile> iterator() { return new Iter(percents, percentiles); }
Example #8
Source File: SearchAggregationParser.java From sql4es with Apache License 2.0 | 4 votes |
/** * Parse an aggregation result based on one or more aggregated terms * @param terms * @param rs * @param row * @throws SQLException */ private void dfsAggregations(Terms terms, ESResultSet rs, List<Object> row) throws SQLException{ List<Object> currentRow = Utils.clone(row); String columnName = terms.getName(); if(!rs.getHeading().hasLabel(columnName)) throw new SQLException("Unable to identify column for aggregation named "+columnName); Column aggCol = rs.getHeading().getColumnByLabel(columnName); for(Terms.Bucket bucket : terms.getBuckets()){ if (bucket instanceof StringTerms.Bucket) { aggCol.setSqlType(Types.VARCHAR); } else if (bucket instanceof LongTerms.Bucket) { aggCol.setSqlType(Types.TIMESTAMP); //ToDO: chack Timestamp } boolean metricAggs = false; List<Aggregation> aggs = bucket.getAggregations().asList(); if(aggs.size() == 0){ currentRow.set(aggCol.getIndex(), bucket.getKey()); metricAggs = true; }else for(Aggregation agg : bucket.getAggregations().asList()){ if(agg instanceof Terms){ currentRow.set(aggCol.getIndex(), bucket.getKey()); dfsAggregations((Terms)agg, rs, currentRow); }else{ if(metricAggs == false){ currentRow.set(aggCol.getIndex(), bucket.getKey()); metricAggs = true; } String metricName = agg.getName(); if(!rs.getHeading().hasLabel(metricName)) throw new SQLException("Unable to identify column for aggregation named "+metricName); Column metricCol = rs.getHeading().getColumnByLabel(metricName); // ToDo: check it if (agg instanceof InternalAvg) { currentRow.set(metricCol.getIndex(), ((InternalAvg) agg).getValue()); } else if (agg instanceof InternalCardinality) { currentRow.set(metricCol.getIndex(), ((InternalCardinality) agg).getValue()); } else if (agg instanceof InternalMax) { currentRow.set(metricCol.getIndex(), ((InternalMax) agg).getValue()); } else if (agg instanceof InternalMin) { currentRow.set(metricCol.getIndex(), ((InternalMin) agg).getValue()); } else if (agg instanceof Percentile) { currentRow.set(metricCol.getIndex(), ((Percentile) agg).getValue()); } else if (agg instanceof InternalSum) { currentRow.set(metricCol.getIndex(), ((InternalSum) agg).getValue()); } else if (agg instanceof InternalValueCount) { currentRow.set(metricCol.getIndex(), ((InternalValueCount) agg).getValue()); } else if (agg instanceof InternalNumericMetricsAggregation.SingleValue) { currentRow.set(metricCol.getIndex(), ((InternalNumericMetricsAggregation.SingleValue) agg).getValueAsString()); } else { // ToDo: I don't know ( currentRow.set(metricCol.getIndex(), agg.getName()); } } } if(metricAggs){ rs.add(currentRow); currentRow = Utils.clone(row); } currentRow = Utils.clone(row); } }