合并 Neo4j 中的现有记录,删除重复项,保持关系 [英] Merge existing records in neo4j, remove duplicates, keep relationships
本文介绍了合并 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
是我正在寻找的类型.
推荐答案
如果你想在 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屋!
查看全文