Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Nested Aggregation

More info about nested aggregation is in the official elasticsearch docs

A special single bucket aggregation that enables aggregating nested documents.

Simple example

{
    "aggregations" : {
        "resellers" : {
            "nested" : {
                "path" : "resellers"
            },
            "aggregations" : {
                "min_price" : { "min" : { "field" : "resellers.price" } }
            }
        }
    }
}

And now the query via DSL:

$minAggregation = new MinAggregation('min_price', 'resellers.price');
$nestedAggregation = new NestedAggregation('resellers', 'resellers');
$nestedAggregation->addAggregation($minAggregation);

$search = new Search();
$search->addAggregation($nestedAggregation);

$queryArray = $search->toArray();