In the database I have a label Person
which contains nodes with properties: firstname, gender, lastname, id
.
I have a CSV file that contains relationship information such as:
id sibling
1 3,4,5
What I am trying to do is create relationship between the id
and the values in the sibling
column.
I am using the following code to do so:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM
'file:///relationship.csv' AS line1
WITH line1, split(line1.sibling, ",") as siblings
UNWIND siblings as sibling
MERGE (p:Person{id:line1.id})
MERGE (k:Person{id:sibling})
MERGE (p)-[:SIBLING_OF]->(k)
but this approach creates new nodes that have only id
property, instead of connecting the nodes that already exist in the database.
The weird thing is when I use this query:
MATCH (p:Person)
WHERE p.id='123'
RETURN p
it returns only the node that was previously in the database (containing id, firstname, gender, lastname and id properties), without the newly created relationship, but when I try to return the node with a relationship, such as:
MATCH (p:Person)-[SIBLING_OF]-(k:Person)
WHERE p.id='123
RETURN p,k
the newly created k
node gets returned that has only id
property.
Does anyone know what I am doing wrong with the query?