Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Avg Aggregation

More info about avg aggregation is in the official elasticsearch docs

A single-value metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents.

Simple example

{
    "aggregations": {
        "agg_avg_grade": {
            "avg": {
                "field": "grade"
            }
        }
    }
}

And now the query via DSL:

$avgAggregation = new AvgAggregation('avg_grade');
$avgAggregation->setField('grade');

$search = new Search();
$search->addAggregation($avgAggregation);

$queryArray = $search->toArray();