Merge duplicate nodes into one with relationship


(Kailash) #1

I have a requirements to merge the duplicate nodes and keep one copy. Issue I am facing is , when i merge nodes, there will be duplicate relationship created. Instead i wants to merge the relationship as well without duplicates.
i tried, but then the relationship is getting duplicated. i want to merge all relationship and keep one copy.

Could you please give some suggestions?


(Kailash) #2

I have put it in stackoverflow as well. an immediate help would be appreciated.

(Stefan Armbruster) #3

APOC's mergeNodes : ?

(Kailash) #4

i am using earlier version of neo4j.

something like this , MATCH (p:People{name:"person1"}) WITH as name, collect(p) as nodes, count( ) as cnt WHERE cnt > 1 WITH head(nodes) as first, tail(nodes) as rest UNWIND rest AS to_delete MATCH (to_delete)-[r:HAS_MET]->(e:name) MERGE (first)-[r1:HAS_MET]->(e) on create SET r1=r SET to_delete.isDuplicate=true RETURN count( ); [link]… . but here i know only one relationship(HAS_MET) will be consider, how do i consider all the relationship once. –

could you please suggest

(Stefan Armbruster) #5

earlier version

Which one?