title: Aggregations on most recent document in group using elasticsearch
body: <p>Suppose there are several documents per person that contain values:</p>
  
  <pre><code>{
    "name": "John",
    "value": 1,
    "timestamp": 2014-06-15
  }
  
  {
    "name": "John",
    "value": 2,
    "timestamp": 2014-06-16
  }
  
  {
    "name": "Sam",
    "value": 2,
    "timestamp": 2014-06-15
  }
  
  {
    "name": "Sam",
    "value": 3,
    "timestamp": 2014-06-16
  }
  
  </code></pre>
  
  <ol>
  <li>How do I get a list of the most recent documents for each person?</li>
  <li>How do I get an average of the values for the list of the most recent documents for each person? Given the sample data, this would be 2.5, not 2.</li>
  </ol>
  
  <p>Is there some combination of buckets and metrics that could achieve this result? Will I need to implement a custom aggregator as part of a plugin, or must this sort of computation be performed in memory?</p>