1
votes

I have a Neo4J database with a bunch of employee and consultant nodes, with a relationship consults pointing from a consultant to an employee node. A consultant can consult many employees and an employee can have multiple consultants.

My issue is that some (not all!) of the consultants are employees as well. How do I go about merging nodes to have two labels to specify those consultants that are employees?

I exported my data from Postgres and imported it to Neo so I have a bunch of nodes like the examples below:

The name field on all the nodes is unique. Is there a way to match nodes with the same name, create a new node with the new title, and delete the old nodes?

(c:Consultant {name:“Consultant1”}) (e:Employee {name:“Consultant1"})

Desired fix: (p:Consultant:Employee {name:“Consultant1”)

1

1 Answers

1
votes

The APOC procedure apoc.refactor.mergeNodes should work for your use case.

It merges multiple nodes from a list into the first node, and also merges all their relationships as well.