org.elasticsearch.search.aggregations.metrics.min.InternalMin Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.metrics.min.InternalMin. 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: Utils.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
public static Map<String, Number> toStats(Aggregation statAggregation) {
    if (statAggregation instanceof InternalExtendedStats) {
        return Utils.createStatsResponse((InternalExtendedStats) statAggregation);
    }
    else if (statAggregation instanceof InternalStats) {
        return Utils.createStatsResponse((InternalStats) statAggregation);
    }
    else if (statAggregation instanceof InternalMax) {
        return Utils.createStatResponse((InternalMax) statAggregation);
    }
    else if (statAggregation instanceof InternalMin) {
        return Utils.createStatResponse((InternalMin) statAggregation);
    }
    else if (statAggregation instanceof InternalAvg) {
        return Utils.createStatResponse((InternalAvg) statAggregation);
    }
    else if (statAggregation instanceof InternalSum) {
        return Utils.createStatResponse((InternalSum) statAggregation);
    }
    else if (statAggregation instanceof InternalValueCount) {
        return Utils.createStatResponse((InternalValueCount) statAggregation);
    }
    return new HashMap<>();
}
 
Example #2
Source File: SearchAggregationParser.java    From sql4es with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
	}
}
 
Example #3
Source File: Utils.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
public static Map<String, Number> createStatResponse(InternalMin statAggregation) {
    return ImmutableMap.of(MIN, statAggregation.getValue());
}