Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare IDs between two indices in elasticsearch

I have two indices in an elasticsearch cluster, containing what ought to be the same data in two slightly different formats. However, the number of records are different. The IDs of each document should be the same. Is there a way to extract a list of what IDs are present in one index but not the other?

like image 374
Beornwulf Avatar asked Oct 24 '25 20:10

Beornwulf


1 Answers

If your two indices have the same type where these documents are stored, you can use something like this:

GET index1,index2/_search
{
  "size": 0,
  "aggs": {
    "group_by_uid": {
      "terms": {
        "field": "_uid"
      },
      "aggs": {
        "count_indices": {
          "cardinality": {
            "field": "_index"
          }
        },
        "values_bucket_filter_by_index_count": {
          "bucket_selector": {
            "buckets_path": {
              "count": "count_indices"
            },
            "script": "params.count < 2"
          }
        }
      }
    }
  }
}

The query above works in 5.x. If your ID is a field inside a document, that's even better to test.

like image 60
Andrei Stefan Avatar answered Oct 26 '25 16:10

Andrei Stefan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!