'removing duplicate city names using elastic search

{
  "size" : 0,
  "query" : {
    "wildcard" : {
      "city.keyword" : {
        "wildcard" : "MEXI*"
      }
    }
  },
  "aggregations" : {
    "groupby" : {
      "composite" : {
        "size" : 10,
        "sources" : [
          {
            "city" : {
              "terms" : {
                "field" : "city.keyword",
                "order" : "asc"
              }
            }
          }
        ]
      }
    }
  }
}

This is the query I am using to remove the duplicate cities, but still, there are many cities with different entries such as MEXICO CITY, MEXICO CITY for MEXICO CITY or MEXICO D.F.,MEXICO DF,MEXICO, D.F. for MEXICO D.F.. Is there a way to remove these duplicates and get result as one city in ES



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source