From 041a90d638152c39e77c9a1b93673c0066b08015 Mon Sep 17 00:00:00 2001
From: Aivaras Gotovskis <aivaras.gotovskis@ongr.io>
Date: Fri, 10 Jul 2015 12:07:04 +0300
Subject: [PATCH] Add Reverse Nested aggregation doc.

---
 docs/Aggregation/ReverseNested.md | 60 +++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 docs/Aggregation/ReverseNested.md

diff --git a/docs/Aggregation/ReverseNested.md b/docs/Aggregation/ReverseNested.md
new file mode 100644
index 0000000..7ef138a
--- /dev/null
+++ b/docs/Aggregation/ReverseNested.md
@@ -0,0 +1,60 @@
+# 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
-- 
GitLab