I am new to Neo4j and I have been stuck on a simple problem for a whole day. It should be a very simple fix but I just can't get it right! I am trying to model a company's hierarchical structure (from CEO to interns). I have a cvs file with the Employee_ID numbers and their job titles. In the same file I have another column with the ID numbers of the Employees' managers. So in each row I have 3 cells: Employee's ID, job title, Employee's manager's ID, and I have 30 rows(for now).
(For example: next to Employee John's ID there is employee Sam's ID because Sam is John's manager. Sam also appear in the Employee column, and next to his ID number there is Mark's ID, because Mark is Sam's manager..and so on)
It seems very similar to the classic example Actor-[ACTED_IN]->Movie, but in this case I don't have 30 actor nodes and 30 movie nodes, and I am not sure how to build 30 relationship between the same 30 nodes.
Every time I try to create the WORKS_UNDER relationship I end up creating new nodes and I can't get Neo4j to realise that the nodes on the right side of the relationship are already in the graph.
I am sure this is a simple problem, but as I said, I am new to Neo4j and I could really use the help!
UPDATE: I managed to make it work by adding the managers' IDs as a property in the Employees' nodes.
LOAD CSV WITH HEADERS FROM "file:///Personnel.csv" AS row FIELDTERMINATOR ';'
MERGE (person:Person { employee_ID:row.ID, job_title:row.Jobtitle, manager_ID:row.ManagerID })
WITH *
MATCH (p1:Person)
MATCH (p2:Person)
WHERE p2.employee_ID = p1.manager_ID
MERGE (p1)-[r:WORKS_UNDER]-(p2)
I'm sure there must be a way to do this that doesn't require me to add the managers' IDs as a property, but I can't figure it out :(