title: elasticsearch - trying to find latest time stamp in aggregation
body: <p>I have written a query in elastic search using range on a timestamp field.  I need to find the latest timestamp for each group.  First I perform the query, then group by the name field, then try to select the latest timestamp.  But it is not working.  Any suggestions are appreciated.  Below is my json I use for the search Post query from postman</p>
  
  <p>{
    "query" : {
          "range" : { "timestamp" :  { "gte" :"2016-10-05T15:00:35", "lte" :   "2016-10-06T15:10:35" } } 
      },</p>
  
  <pre><code>"aggs" : {
     "groupbyname" : { 
          "terms" : {
              "field" : "name"
              },  
              "aggs" : {
                  "selectlatesttimestamp" :  {
                  "max" : {
                      "field" : "timestamp"
                  }
              }
          }
  
      }
  }
  </code></pre>
  
  <p>} </p>