title: Sub-aggregate a multi-level nested composite aggregation
body: <p>I'm trying to set up a search query that should composite aggregate a collection by a multi-level nested field and give me some sub-aggregation metrics from this collection. I was able to fetch the composite aggregation with its buckets as expected but the sub-aggregation metrics come with <code>0</code> for all buckets. I'm not sure if I am failing to correctly point out what fields the sub-aggregation should consider or if it should be placed inside a different part of the query.</p>
  <p>My collection looks similar to the following:</p>
  <pre><code>{
    id: '32ead132eq13w21',
    statistics: {
      clicks: 123,
      views: 456
    },
    categories: [{ //nested type
      name: 'color',
      tags: [{ //nested type
        slug: 'blue'
      },{
        slug: 'red'
      }]
    }]
  }
  
  </code></pre>
  <p>Bellow you can find what I have tried so far. All buckets come with <code>clicks</code> sum as <code>0</code> even though all documents have a set <code>clicks</code> value.</p>
  <pre><code>GET /acounts-123321/_search
  {
    &quot;size&quot;: 0,
    &quot;aggs&quot;: {
      &quot;nested_categories&quot;: {
       &quot;nested&quot;: {
          &quot;path&quot;: &quot;categories&quot;
       },
       &quot;aggs&quot;: {
             &quot;nested_tags&quot;: {
               &quot;nested&quot;: {
                  &quot;path&quot;: &quot;categories.tags&quot;
                },
                &quot;aggs&quot;: {
                  &quot;group&quot;: {
                    &quot;composite&quot;: {
                       &quot;size&quot;: 100,
                       &quot;sources&quot;: [
                         { &quot;slug&quot;: { &quot;terms&quot; : { &quot;field&quot;: &quot;categories.tags.slug&quot;} }}
                       ]
                     },
                     &quot;aggregations&quot;: {
                       &quot;clicks&quot;: {
                         &quot;sum&quot;: {
                           &quot;field&quot;: &quot;statistics.clicks&quot;
                         }
                       }
                     }
                  }
                }
              }
            }
         }
    }
  }
  </code></pre>
  <p>The response body I have so far:</p>
  <pre><code>{
    &quot;took&quot; : 6,
    &quot;timed_out&quot; : false,
    &quot;_shards&quot; : {
      &quot;total&quot; : 1,
      &quot;successful&quot; : 1,
      &quot;skipped&quot; : 0,
      &quot;failed&quot; : 0
    },
    &quot;hits&quot; : {
      &quot;total&quot; : {
        &quot;value&quot; : 1304,
        &quot;relation&quot; : &quot;eq&quot;
      },
      &quot;max_score&quot; : null,
      &quot;hits&quot; : [ ]
    },
    &quot;aggregations&quot; : {
      &quot;nested_categories&quot; : {
        &quot;doc_count&quot; : 1486,
        &quot;nested_tags&quot; : {
          &quot;doc_count&quot; : 1486,
          &quot;group&quot; : {
            &quot;buckets&quot; : [
              {
                &quot;key&quot; : {
                  &quot;slug&quot; : &quot;red&quot;
                },
                &quot;doc_count&quot; : 268,
                &quot;clicks&quot; : {
                  &quot;value&quot; : 0.0
                }
              }, {
                &quot;key&quot; : {
                  &quot;slug&quot; : &quot;blue&quot;
                },
                &quot;doc_count&quot; : 122,
                &quot;clicks&quot; : {
                  &quot;value&quot; : 0.0
              },
              .....
            ]
          }
        }
      }
    }
  }
  </code></pre>