title: Elasticsearch - Count duplicated and unique values
body: <p>I have the following json</p>
  
  <pre><code>[
   {"firstname": "john", "lastname": "doe"},
   {"firstname": "john", "lastname": "smith"},
   {"firstname": "jane", "lastname": "smith"},
   {"firstname": "jane", "lastname": "doe"},
   {"firstname": "joe", "lastname": "smith"},
   {"firstname": "joe", "lastname": "doe"},
   {"firstname": "steve", "lastname": "smith"},
   {"firstname": "jack", "lastname": "doe"}
  ]
  </code></pre>
  
  <p>I want to get a count of duplicate firstnames</p>
  
  <p>duplicates count 3</p>
  
  <p>Count of non-duplicate firstnames </p>
  
  <p>non-duplicates count 2</p>
  
  <p>I tried to count the number of buckets, but it seems to count all buckets whether it's duplicate or non-duplicate</p>
  
  <pre><code>GET mynames/_search
  {
  "aggs" : {
      "name_count" : {
          "terms" : {
              "field" : "firstname.keyword",
              "min_doc_count": 2
          }
      },
  "count":{
    "cardinality": {
      "field": "firstname.keyword"
    }
  }
  }
  </code></pre>