
Elasticsearch 8.x Cookbook
By :

Searching for results is the main activity of a search engine, so aggregations are very important because they often help augment the results.
Aggregations can be executed along with the search by performing analytics on the results that are returned.
You will need an up-and-running Elasticsearch installation, which we described how to get in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
You will also need the Python packages that we installed in the Creating a client recipe of this chapter.
The code for this recipe can be found in the ch15/code/aggregation.py
file.
To extend a query with aggregations, you need to define an aggregation section, as we saw in Chapter 7, Aggregations. In the case of the official Elasticsearch client, you can add the aggregation DSL to the search dictionary to provide aggregations. To set this up, perform the following steps...