cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

No relationship generated when optional node property is missing

I am loading a data set with some missing values. E.g. :Person node always has idNumber, but is sometimes missing dob. I create all the nodes without issues and I have confirmed that there are nodes that have both idNumber and dob and nodes that have idNumber only. The number of loaded nodes matches the number of rows in the input files. Then I try to create a relationship between :Membership and :Person based on memberId and idNumber only:

USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM 'file//my_file.csv' AS row
WITH row
WHERE row.idNumber IS NOT NULL
MERGE (person:Person {idNumber: row:idNumber})
MERGE (membership:Membership {memberId: row.memberId})
CREATE (person)-[:IS_MEMBER]->(membership)

The above statement works only if I load nodes WITHOUT dob property. If nodes have dob property. no relationships are created, even for the nodes that have both idNumber and dob populated. I attempted

MERGE (membership:Membership {memberId: row.memberId, dob:row.dob})

which also failed. How do I create relationships based on a single property? (e.g. I don't care if dob property is present in the node or not, I want to create a relationship based on idNumber and membership ID)

1 ACCEPTED SOLUTION

You are not setting the dob property when you create the node using MERGE.

Elaine

View solution in original post

2 REPLIES 2

You are not setting the dob property when you create the node using MERGE.

Elaine

Edit: you are right, the above solution worked. Thank you!

USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM 'file:///myfile.csv' AS row
FIELDTERMINATOR '\t'
MERGE (personl:Person {idNumber: row.idNumber})
SET person.dob=row.birthday

Then in the next step I apply the above code. The relationship is created only if in the first step when I create node I don't add person.dob. It doesn't matter if I add a MERGE on dob when creating a relationship.