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.

How can I update relationship property from another csv source?

Hi,

I am relatively new to Neo4j and would like to know if the initial set properties of the relationships can be updated via another CSV source.

For example, I've created multiple nodes and relationships like:

FOREACH (IND3 IN (CASE WHEN a.temp = 1 THEN [a.temp] ELSE [] END) | 	
    MERGE (ind3 :Indic3 {Indic3: IND3})
    MERGE (a)-[e_ind3: example_text]->(ind3)
    SET e_ind3.score = 10
    SET e_ind3.temp_id = 3
)

And now I would like to routinely update those scores based on another given csv, rather than changing those scores manually, the format of the csv file is like:

Indic	score
3          5
4	 	   9
5 	       7
6	 	  20

and I have tried the below way

MATCH (a: case)-[RULES]->()

WITH a, RULES
LOAD CSV WITH HEADERS FROM "file:///out_source.csv" AS row
MATCH (a)-[RULE {Indic: row.Indic}]->()
SET RULE.score= row.score

however, although it does change the properties of all relationships, they have all been changed to the last row, all ids become 6 and all scores become 20.

Looking forward to any suggestions. Thanks

1 ACCEPTED SOLUTION

ameyasoft
Graph Maven
Try this:

LOAD CSV WITH HEADERS FROM "file:///out_source.csv" AS row
MATCH (ind3 :Indic3) where ind3.Indic3 = row.Indic
MATCH (a: case)-[r:RULES]->(ind3)
where r.Indic = row.Indic
set r.Score = row.Score

View solution in original post

3 REPLIES 3

ameyasoft
Graph Maven
Try this:

LOAD CSV WITH HEADERS FROM "file:///out_source.csv" AS row
MATCH (ind3 :Indic3) where ind3.Indic3 = row.Indic
MATCH (a: case)-[r:RULES]->(ind3)
where r.Indic = row.Indic
set r.Score = row.Score

Thanks for your suggestion. It sounds about right and it is working when I tried individual one as MATCH (ind) where ind.Indic= 4 MATCH (a)-[r]->(ind) WHERE r.Indic= 4 SET r.score= 5

But when trying within the csv file, it shows (no changes, no records)

Thanks

No worries. I've managed to solve that by adding toInteger(row.Indic) to the code to make sure the formats match. Many thanks