title: Get latest record in group in ElasticSearch
body: <p>I have the following table structure</p>
  
  <pre><code>change_id    saveDate     id
  -------------------------------
  1            2014-04-01  205
  2            2014-05-01  205
  3            2014-03-31  111
  4            2014-04-01  111
  5            2014-04-01  333
  </code></pre>
  
  <p>Now I want to get the latest record for specific ids = [205, 111]. 
  I should get the records with change_id [2,4].</p>
  
  <p>My ElasticSearch query is so far:</p>
  
  <pre><code>    {
          "fields": [
              "Something.id",
              "Something.change_id",
              "Something.saveDate"
          ],
          "query": {
              "terms": {
                  "Something.id": [
                      "2015",
                      "111"
                  ]
              }
          },
          "sort": [
              {
                  "Something.saveDate": {
                      "order": "desc"
                  }
              }
          ],
          "aggs": {
              "id": {
                  "terms": {
                      "field": "Something.id",
                      "size": 20
                  }
              }
          }
      }
  </code></pre>
  
  <p>I am getting result of 4 rows change_id=[2, 1, 4, 3], which sorted desc by saveDate.</p>
  
  <p>How can I filter that using query and get two rows where change_id=[4, 2] ?</p>