在 Neo4j 1.8 中查找重复节点的有效方法? [英] An effective way to lookup duplicate nodes in Neo4j 1.8?

查看:131
本文介绍了在 Neo4j 1.8 中查找重复节点的有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式定位 Neo4j 1.8 数据库中的所有重复节点(使用 Neo4j 1.8).需要检查的节点都有一个(非索引)属性 externalId,我想为其查找重复项.这是我得到的 Cypher 查询:

I'm trying to programmatically locate all duplicate nodes in a Neo4j 1.8 database (using Neo4j 1.8). The nodes that need examination all have a (non-indexed) property externalId for which I want to find duplicates of. This is the Cypher query I've got:

            START n=node(*), dup=node(*) WHERE 
                HAS(n.externalId) AND HAS(dup.externalId) AND 
                n.externalId=dup.externalId AND 
                ID(n) < ID(dup) 
                RETURN dup

数据中的节点少于 10K,并且具有 externalId 的节点少于 1K.上面的查询正在运行,但似乎性能不佳.有没有一种内存消耗更少的方法来做到这一点?

There are less than 10K nodes in the data and less than 1K nodes with an externalId. The query above is working but seems to perform badly. Is there a less memory consuming way to do this?

推荐答案

试试这个查询:

START n=node(*)
WHERE HAS(n.externalId)
WITH n.externalId AS extId, COLLECT(n) AS cn
WHERE LENGTH(cn) > 1
RETURN extId, cn;

它避免了节点的笛卡尔积.它找到不同的 externalId 值,收集所有具有相同 id 的节点,然后过滤掉非重复的 id.结果中的每一行都将包含一个 externalId 以及具有该 ID 的重复节点的集合.

It avoids taking the Cartesian product of your nodes. It finds the distinct externalId values, collects all the nodes with the same id, and then filters out the non-duplicated ids. Each row in the result will contain an externalId and a collection of the duplicate nodes with that id.

这篇关于在 Neo4j 1.8 中查找重复节点的有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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