Executing nested aggregation

Nested aggregations allow us to execute analysis on nested documents. When working with complex structures, nested objects are very common.

Getting ready

You need a working ElasticSearch cluster and an index populated with the script available at https://github.com/aparo/elasticsearch-cookbook-second-edition.

How to do it...

To execute nested aggregations, we will perform the steps given as follows:

  1. We must index documents with a nested type, as discussed in the Managing nested objects recipe in Chapter 3, Managing Mapping:
    { "product" : { "properties" : { "resellers" : { "type" : "nested" "properties" : { "username" : { "type" : "string", "index" : "not_analyzed" }, "price" : { "type" : "double" } } }, "tags" : { "type" ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.