Skip to content
Snippets Groups Projects
Commit 041a90d6 authored by Aivaras Gotovskis's avatar Aivaras Gotovskis
Browse files

Add Reverse Nested aggregation doc.

parent 0f24a616
No related branches found
No related tags found
No related merge requests found
# Reverse Nested Aggregation
> More info about reverse nested aggregation is in the [official elasticsearch docs][1]
A special single bucket aggregation that enables aggregating on parent docs from nested documents.
## Simple example
```JSON
{
"aggregations": {
"agg_comments": {
"nested": {
"path": "comments"
},
"aggregations": {
"agg_top_usernames": {
"terms": {
"field": "comments.username"
},
"aggregations": {
"agg_comment_to_issue": {
"reverse_nested": {},
"aggregations": {
"top_tags_per_comment": {
"terms": {
"field": "tags"
}
}
}
}
}
}
}
}
}
}
```
And now the query via DSL:
```php
$tagsTermsAggregations = new TermsAggregation('top_tags_per_comment', 'tags');
$reverseNestedAggregation = new ReverseNestedAggregation('comment_to_issue');
$reverseNestedAggregation->addAggregation($tagsTermsAggregations);
$usernameTermsAggregation = new TermsAggregation('top_usernames', 'comments.username');
$usernameTermsAggregation->addAggregation($reverseNestedAggregation);
$nestedAggregation = new NestedAggregation('comments', 'comments');
$nestedAggregation->addAggregation($usernameTermsAggregation);
$search = new Search();
$search->addAggregation($nestedAggregation);
$queryArray = $search->toArray();
```
[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment