我在elasticsearch集群中有两个索引,包含两个略有不同格式的相同数据。但是,记录的数量是不同的。每个文档的ID应该相同。有没有办法提取一个索引中存在哪些ID而不是另一个索引的列表?
答案 0 :(得分:1)
如果您的两个索引与存储这些文档的类型相同,则可以使用以下内容:
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是文档中的字段,则测试更好。
答案 1 :(得分:0)
对于遇到此问题的任何人,如果您遵循 Elasticsearch 中 ID 和版本概念的约定,Scrutineer (https://github.com/Aconex/scrutineer/) 会提供这种功能。