title: Elastic Search SUM of aggregated values
body: <p>We are using elastic search to get some statics. </p>
  
  <ol>
  <li>I need to get average values for each group.</li>
  <li>Sum all this values</li>
  </ol>
  
  <p>So far, step no. 1 was pretty straight forward. However I really don't know how to sum all values at the end. Is this possible? If yes, how?.</p>
  
  <p>Thanks for suggestions.
  Here is my aggs query > </p>
  
  <pre><code>{  
     "query":{  
        "filtered":{  
           "query":{  
              "query_string":{  
                 "analyze_wildcard":true,
                 "query":"*"
              }
           }
        }
     },
     "aggs":{  
        "2":{  
           "terms":{  
              "field":"person",
              "size":5000,
              "order":{  
                 "1":"desc"
              }
           },
           "aggs":{  
              "1":{  
                 "avg":{  
                    "field":"company"
                 }
              }
           }
        }
     }
  }
  </code></pre>