The AggregateExpression class allows performing aggregation over a multi-valued numeric FieldExpression.
*Available Functions (See here ):*
- AVG - computes the average over a multi-value field/expression
- MIN - computes the minimum value over a multi-value field/expression
- MAX - computes the maximum value over a multi-value field/expression
- SUM - computes the sum over a multi-value field/expression
- STDEV - computes the standard deviation over a multi-value field/expression
- COUNT - counts the number of values in a multi-value field/expression
- FIRST - returns the first value for a multi-value field/expression
- LAST - returns the last value for a multi-value field/expression
- DISTINCT - returns only the unique values for a multi-value field/expression
Example:
// Compute the average over all field values // Assumes the "value" field is a numeric multi-value field QueryRequest request = new QueryRequest("*:*"); request.addField( new AggregateExpression(AggregateExpression.AVG, new StoredField("temperatures")) ); // ... (Perform Search)
REST Syntax:
FUNCTIONNAME(FIELDEXPRESSION)
- FUNCTIONNAME - any of the available field function names specified above. (AVG, SUM, etc)
- FIELDEXPRESSION - field expression to apply the function to.
Example:
# Compute a bunch of aggregation functions over a multi value field # Assumes the "value" field is a numeric multi-value field &fields=AVG(value),MIN(value),MAX(value),SUM(value),STDEV(value),COUNT(value),FIRST(value),LAST(value)