title: Nested array of objects aggregation in Elasticsearch
body: <p>Documents in the Elasticsearch are indexed as such</p>
  <p>Document 1</p>
  <pre><code>{
    &quot;task_completed&quot;: 10
    &quot;tagged_object&quot;: [
      {
        &quot;category&quot;: &quot;cat&quot;,
        &quot;count&quot;: 10
      },
      {
        &quot;category&quot;: &quot;cars&quot;,
        &quot;count&quot;: 20
      }
    ]
  } 
  </code></pre>
  <p>Document 2</p>
  <pre><code>{
    &quot;task_completed&quot;: 50
    &quot;tagged_object&quot;: [
      {
        &quot;category&quot;: &quot;cars&quot;,
        &quot;count&quot;: 100
      },
      {
        &quot;category&quot;: &quot;dog&quot;,
        &quot;count&quot;: 5
      }
    ]
  } 
  </code></pre>
  <p>As you can see that the value of the category key is dynamic in nature. I want to perform a similar aggregation like in SQL with the group by category and return the sum of the count of each category.</p>
  <p>In the above example, the aggregation should return
  cat: 10,
  cars: 120 and
  dog: 5</p>
  <p>Wanted to know how to write this aggregation query in Elasticsearch if it is possible. Thanks in advance.</p>