Select unique records from a query in the elasticsearch datasource

I’m using the elasticsearch-monitoring dashboard (Elasticsearch Monitoring based on X-Pack stats dashboard for Grafana | Grafana Labs) but I’ve noticed an issue with it.
When multiple cluster monitoring stats are shipped to a single monitoring node, the grafana dashboard picks up the fact that there are multiple clusters, but the Cluster Overview panel lists duplicate data (see here as an example: Elasticsearch-monitoring - Duplicate data when multiple clusters are writing monitoring data · Issue #4 · crab86/grafana-plei · GitHub)

I want to fix this, but I’m unsure of how to do it.
The targets are set as:

          "targets": [
            {
              "bucketAggs": [],
              "metrics": [
                {
                  "field": "select field",
                  "id": "1",
                  "meta": {},
                  "settings": {
                    "size": 5
                  },
                  "type": "raw_document"
                }
              ],
              "query": "cluster_stats AND cluster_uuid:$Cluster_UUID",
              "refId": "A",
              "timeField": "timestamp"
            }
]

I want to make sure that the records coming back are unique in terms of cluster_uuid or cluster_name.

Does anyone know how I would change the query to make that work?

I ended up doing it myself in the end by using a Group By Transformation and either Grouping-By or Calculating column values, depending on how they should be handled.