Date histogram to count unique users per month in a year

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser): Opensearch 2.15

Describe the issue:
How we can calculate unique users per month for given year, but if user is already accounted for one month, then it should not consider in next months.

Tried date_histogram with cardinality but its counting unique users per month, and it is giving repeating counts.

Able to solve this issue with scripted_metric (map-reduce) and it is giving correct counts, but this is very memory intensive and not performing for large datasets. So, want to take date_histogram approach which is quite faster in nature compared to scripts.

Configuration:

{
  "size": 0,
  "aggs": {
    "monthly_counts": {
      "composite": {
        "size": 1000,
        "sources": [
          {
            "month": {
              "date_histogram": {
                "field": "date",
                "calendar_interval": "month",
                "format": "yyyy-MM",
                "order": "asc"
              }
            }
          }
        ]
      },
      "aggs": {
        "distinct_users": {
          "cardinality": {
            "field": "user"
          }
        }
      }
    }