How to get duplicate field values in elastic search by field name without knowing its value

You can use Terms Aggregation for this.

POST <index>/<type>/_search?search_type=count
{
    "aggs": {
        "duplicateNames": {
            "terms": {
                "field": "EmployeeName",
                "size": 0,
                "min_doc_count": 2
            }
        }
    }
}

This will return all values of the field EmployeeName which occur in at least 2 documents.


This would be the query with the current Elasticsearch version:

GET <index>/_search
{
  "size": 0,
  "aggs": {
    "duplicateNames": {
       "terms": {
         "field": "EmployeeName",
         "min_doc_count": 2
       }
     }
  }
}