We can always combine searches, filters bucket aggregations, and metric aggregations to get a more and more complex analysis. Until now, we have seen single levels of aggregations; however, as explained in the aggregation syntax section earlier, an aggregation can contain multiple levels of aggregations within. However, metric aggregations cannot contain further aggregations within themselves. Also, when you run an aggregation, it is executed on all the documents in the index for a document type if specified on a match_all query context, but you can always use any type of Elasticsearch query with an aggregation. Let's see how we can do this in Python and Java clients.
Python example
query = { "query": { "match": { "text": "crime" } }, "aggs": { "hourly_timeline": { "date_histogram": { "field": "created_at", "interval": "hour" }, "aggs": { "top_hashtags": { "terms": { ...