Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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" : "string", "index":"not_analyzed"}
        }
      }
    }
  2. To return the minimum price the products can be purchased at, we create a nested aggregation with code similar to this one:

    curl -XGET...