0
votes

I have a Neo4J Graph and want to add a new Property on the Relationships based on the ID of the Relationship, which is already set. The ID is a Property and looks like this:

id:16_0beta1_1b500480_1221807483755_439038_8369

In a CSV-File I have stored 400 IDs and a type corresponding to the IDs. Neo4J should load the CSV-File and look through all relationships. When a Relationship ID matches an ID from the CSV-File it should set the new Property like this: set r.SysML=row.type and create a new Property on the Relationship:

SysML:Block

For the nodes the following clause worked well:

LOAD CSV WITH HEADERS FROM "file:///SysML.csv" AS row 
merge(n:name {id:row.sysID}) 
on match set n.SysML=row.type

For Relationship Property i tried:

LOAD CSV WITH HEADERS FROM "file:///SysML.csv" AS row 
merge ()-[r:rel {id:row.sysID}]->() 
on match set r.SysML=row.type

I couldn't solve it even with many variations of the relationship...

1
This query is correct and should work. You might have missed something in matching query. Could you check if following query returns anything? LOAD CSV WITH HEADERS FROM "file:///SysML.csv" AS row MATCH ()-[r:rel {id:row.sysID}]->() RETURN r LIMIT 10Rajendra Kadam
Yes it returns me all the relationships with the label 'rel' but when i do my query it gives an Error: that Neo4J doesn't like the 'on match set' part...AlabaSchmallaba
What is the exact error message?cybersam

1 Answers

0
votes

You should NEVER do this:

merge ()-[r:rel {id:row.sysID}]->()

If the relationship does not already exist, that clause would create a new relationship between 2 brand new nodes having no labels or properties (and your on match clause would also not be applied).

Since your question indicates you just want to update the SysML property of existing rel relationships, you should use MATCH instead of MERGE:

LOAD CSV WITH HEADERS FROM "file:///SysML.csv" AS row 
MATCH ()-[r:rel {id: row.sysID}]->() 
SET r.SysML = row.type

By the way, it would be more efficient if you qualified the end nodes (e.g., by supplying labels, or even property values) to avoid having to scan through every relationship in the DB.