Finally, we come to our last business requirement: allow managers to run
analytics over the employee directory. Elasticsearch has functionality called
aggregations, which allow you to generate sophisticated analytics over your
data. It is similar to GROUP BY in SQL, but much more powerful.

For example, let’s find the most popular interests enjoyed by our employees:

We can see that two employees are interested in music, one in forestry, and one
in sports. These aggregations are not precalculated; they are generated on
the fly from the documents that match the current query. If we want to know
the popular interests of people called Smith, we can just add the
appropriate query into the mix:

The output is basically an enriched version of the first aggregation we ran.
We still have a list of interests and their counts, but now each interest has
an additional avg_age, which shows the average age for all employees having
that interest.

Even if you don’t understand the syntax yet, you can easily see how complex aggregations and groupings can be accomplished using this feature.
The sky is the limit as to what kind of data you can extract!