title: Elasticsearch filter document group by field
body: <p>I have some documents:</p>
  
  <pre><code>{"name": "John", "district": 1},
  {"name": "Mary", "district": 2},
  {"name": "Nick", "district": 1},
  {"name": "Bob", "district": 3},
  {"name": "Kenny", "district": 1}
  </code></pre>
  
  <p>How can I filter/select distinct documents by district?</p>
  
  <pre><code>{"name": "John", "district": 1},
  {"name": "Mary", "district": 2},
  {"name": "Bob", "district": 3}
  </code></pre>
  
  <p>In SQL, I can use GROUP BY. I tried terms aggregation but it only returned count distinct.</p>
  
  <pre><code>"aggs": {
    "distinct": {
      "terms": {
        "field": "district",
        "size": 0
      }
    }
  }
  </code></pre>
  
  <p>Thank for your help! :-)</p>