How can we compare two indices in elasticsearch which are expected to be same?

I have a task which deals with comparing two indices on specific fields. I tried this query but I am not sure about the reliability of this query to compare?

I have tried below query in Kibana. Please let me know if this is correct and if there are better ways to compare two indices.

GET prod_hcpcumulativepredictedconvertedpatientskpi_gsk_brandb_lott_ml_asthma_us_2023_12_04_00001,test_prod_hcpcumulativepredictedconvertedpatientskpi_gsk_brandb_lott_ml_asthma_us_2023_12_04_00001/_search
{
  "size": 0,
  "runtime_mappings": {
    "type_and_promoted": {
      "type": "keyword",
      "script": "emit(doc['patient_id'].value + ' ' + doc['refresh_yearmonth'].value)"
    }
  },
  "aggs": {
    "group_by_type_and_promoted": {
      "terms": {
        "field": "type_and_promoted"
      },
      "aggs": {
        "count_indices": {
          "cardinality": {
            "field": "type_and_promoted"
          }
        },
        "values_bucket_filter_by_index_count": {
          "bucket_selector": {
            "buckets_path": {
              "count": "count_indices"
            },
            "script": "params.count < 2"
          }
        }
      }
    }
  }
}
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 6,
    "successful" : 6,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "group_by_type_and_promoted" : {
      "doc_count_error_upper_bound" : 6,
      "sum_other_doc_count" : 741804,
      "buckets" : [
        {
          "key" : "1000020919 20200608",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000020919 20200706",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000020919 20200803",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000020919 20200907",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000020919 20201005",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000020919 20201102",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000204760 20220808",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000204760 20220905",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000204760 20221003",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        },
        {
          "key" : "1000204760 20221107",
          "doc_count" : 2,
          "count_indices" : {
            "value" : 1
          }
        }
      ]
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.