Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-22-2021 05:02 AM
Hi,
I am trying to load data from a csv file with two columns of people and I want to capture the relationship between them if they are on the same row. I cannot figure out how to create the same node even if the person appears in different columns:
|Person| Friend|
|Joe Bloggs| Jane Bloggs|
|Jane Bloggs| John H|
so Jane Bloggs should only appear as one node.
I got to this point but this will create two different nodes for Jane:
LOAD CSV WITH HEADERS FROM "file:///friends.csv" as friends
WITH friends
WHERE friends.Person IS NOT NULL
MERGE (p:person {Name:friends.Person})
MERGE (f:friend {Name:friends.Friend})
MERGE (p)-[:knows]->(f)
Solved! Go to Solution.
06-22-2021 09:54 AM
It looks like it should create both nodes because they are MERGEd using different labels, right?
Have you thought about or tried using the :person label for all people? I think that is how I might model this, the relationship would indicate the friend status... Simplistically, something like this
LOAD CSV WITH HEADERS FROM "file:///friends.csv" as friends
WITH friends
WHERE friends.Person IS NOT NULL
MERGE (p:person {Name:friends.Person})
MERGE (f:person {Name:friends.Friend})
MERGE (p)-[:knows]->(f)
06-22-2021 09:54 AM
It looks like it should create both nodes because they are MERGEd using different labels, right?
Have you thought about or tried using the :person label for all people? I think that is how I might model this, the relationship would indicate the friend status... Simplistically, something like this
LOAD CSV WITH HEADERS FROM "file:///friends.csv" as friends
WITH friends
WHERE friends.Person IS NOT NULL
MERGE (p:person {Name:friends.Person})
MERGE (f:person {Name:friends.Friend})
MERGE (p)-[:knows]->(f)
06-22-2021 11:33 AM
Thank you Joel, that worked!
All the sessions of the conference are now available online