比较Elasticsearch中两个索引之间的ID [英] Compare IDs between two indices in elasticsearch

查看:37
本文介绍了比较Elasticsearch中两个索引之间的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Elasticsearch集群中有两个索引,其中包含应该是两种略有不同格式的相同数据的索引.但是,记录数是不同的.每个文档的ID应该相同.有没有一种方法可以提取出一个索引中存在哪些ID的列表,而另一种索引中没有?

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?

推荐答案

如果两个索引的类型与这些文档的存储类型相同,则可以使用以下方式:

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"
          }
        }
      }
    }
  }
}

上面的查询在5.x中有效.如果您的ID是文档中的一个字段,那么最好进行测试.

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

这篇关于比较Elasticsearch中两个索引之间的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆