Returning several fields with aggregation

I want to make an aggregation of sum but also return the "group by" fields.

For example, i want to make a query on a school database, to get the average grade on a specific class and study
in SQL i run:
select class, study, examId, avg(grade) from grades group by study, examId
and the result is something like:
class | study | avg(grade) a1 | gymnastics | 85 a1 | mathematics | 87 a2 | gymnastics | 85 a2 | mathematics | 87

so the result contains the group by fields (class and study) and the aggregation result.

I want to make the same query with elastic, and to return all the columns in an aggregation (class, study, avg(grade))

Any idea?
Thanks in advance.
Yuval