title: Sorting after aggregation in Elasticsearch
body: <p>I have docs with this structure:</p>
  
  <pre><code>{
      FIELD1:string,
      FIELD2:
          [ {SUBFIELD:number}, {SUBFIELD:number}...]
  }
  </code></pre>
  
  <p>I want to sort on the result of the sum of numbers in FIELD2.SUBFIELDs:</p>
  
  <pre><code>GET myindex/_search
  {
    "size":0,
    "aggs": {
      "a1": {
        "terms": { 
          "field": "FIELD1",
          "size":0
        },
        "aggs":{
          "a2":{
            "sum":{
              "field":"FIELD2.SUBFIELD"
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>If I do this I obtain buckets not sorted, but I want buckets sorted by "a2" value.
  How I can do this?
  Thank you!</p>