title: Elasticsearch content of bucket aggregation on a nested document
body: <p>I am new to elasticsearch and I try to understand the behaviour of bucket aggregations on a nested field type.</p>
  <p>Let's say I have the following structure:</p>
  <pre><code>{
   &quot;forename&quot;:&quot;John&quot;,
   &quot;lastname&quot;:&quot;Doe&quot;,
   &quot;children&quot;:[
     {
      &quot;gender&quot;:&quot;male&quot;,
      &quot;forname&quot;:&quot;Michael&quot;,
      &quot;education&quot;:[
                   {
                        &quot;instituation&quot;:&quot;middle school&quot;,
                        &quot;name&quot;:&quot;bla&quot;
                   },
                   {
                        &quot;instituation&quot;:&quot;high school&quot;,
                        &quot;name&quot;:&quot;bla bla&quot;
                   }
                  ]
     },
     {
      &quot;gender&quot;:&quot;female&quot;,
      &quot;forname&quot;:&quot;Jane&quot;,
      &quot;education&quot;:[
                   {
                        &quot;instituation&quot;:&quot;middle school&quot;,
                        &quot;name&quot;:&quot;hey&quot;
                   },
                   {
                        &quot;instituation&quot;:&quot;high school&quot;,
                        &quot;name&quot;:&quot;hou&quot;
                   }
                  ]
     }    
   ]
  }
  </code></pre>
  <p>So I can execeute a bucket  ( terms ) ggregation on the children-&gt; gducation-&gt;institution  field for exmaple.  Can you tell  me what the document in the bucket looks like? In the docs they say that each nested Object is stored in a hidden index as a separate document. Does that mean that the reusult would only be the objects  within the education array without the outer fields like lastname?</p>
  <p>As I have to use a nested  aggregation before the  terms aggregation within my query , in the hits  array I can not find the  documents of the second query.
  The example I've given is fictive. In my index the data is far more complex and there are multiple thousands of documents in it  so I cannot print  all the hits.</p>