title: sorting results of aggregation in elasticsearch
body: <p>I have written a query to get the latest records per Id from my ES. 
  But the result of this query only does the inner sorting and chooses the latest records. Now I need the results that I got to be sorted by date. </p>
  
  <p>This is my query: </p>
  
  <pre><code>{
     "size":0,
     "query":{
        "bool":{
           "must":[
              {
                 "match":{
                    "base":"XYZ"
                 }
              },
              {
                 "match":{
                    "Type":"low"
                 }
              }
           ]
        }
     },
     "aggs":{
        "sources":{
           "terms":{
              "field":"Id"
           },
           "aggs":{
              "latest":{
                 "top_hits":{
                    "size":1,
  
                    "_source":{
                       "includes":[
                          "base",
                          "Type"
                       ]
                    },
                    "sort":{
                       "orderDate":"desc"
                    }
                 }
              }
           }
        }
     }
  }
  </code></pre>