合并neo4j中的现有记录,删除重复项,保持关系 [英] Merge existing records in neo4j, remove duplicates, keep relationships

查看:854
本文介绍了合并neo4j中的现有记录,删除重复项,保持关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了性能原因,我使用 CREATE 导入了数百万条记录,现在我想要 MERGE 记录在一起,并保持所有的关系完好。

I've imported my millions of records using CREATE for performance reasons, now I want to MERGE the records together, and keep all the relationships intact.

任何想法?

编辑:

MATCH (c1:company), (c2:company) 
WITH c1, c2 
WHERE c1.name = c2.name 
SET c1=c2

是我在找的东西的类型。

Is the type of thing I'm looking for.

推荐答案

如果你想在cypher中合并节点,你可以这样做:

If you want to merge nodes in cypher you can do something like this:

MATCH (c:Company)
WITH c.name as name, collect(c) as companies, count(*) as cnt
WHERE cnt > 1
WITH head(companies) as first, tail(companies) as rest
LIMIT 1000
UNWIND rest AS to_delete
MATCH (to_delete)<-[r:WORKS_AT]-(e:Employee)
MERGE (first)<-[:WORKS_AT]-(e)
DELETE r
DELETE to_delete
RETURN count(*);

请参阅: http://www.neo4j.org/graphgist?dropbox-14493611%2Fmerge_nodes.adoc

这篇关于合并neo4j中的现有记录,删除重复项,保持关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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