Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-03-2021 02:51 AM
Hello,
I have a CSV with columns a,R1,b,R2,c,r3,d
Here a,b,c and d are the values and R1 is the relationship which connects a and b R2 is the relationship which connects b and c . And R3 with c and d. How do I make this as a query in neo4j.
I'm new to this platform.
Thank you.
06-03-2021 03:03 AM
Hello @karthik1997 and welcome to the Neo4j community
Regards,
Cobra
06-03-2021 03:04 PM
Try this:
Use LOAD CSV
MERGE (a:Test {name: row.a})
MERGE (b:Test {name: row.b})
MERGE (a)-[:R1]-(b)
MERGE (c:Test {name: row.c})
MERGE (b)-[:R2]-(c)
MERGE (d:Test {name: row.d})
MERGE (c)-[:R3]-(d)
06-03-2021 06:53 PM
Hello @ameyasoft
R1 R2 R3 are columns in CSV. Can we add them like [:R1] or do we have to do like [row.R1]. But giving like [row.R1] gave me an error.
06-03-2021 08:34 PM
Try this:
LOAD CSV WITH HEADERS FROM "file:///relations.csv" AS row
MATCH (f:Node), (s:Node)
WHERE f.Name = row.FromNode
AND s.Name = row.ToNode
CALL apoc.create.relationship(f, row.R1,{}, s) YIELD rel
REMOVE rel.noOp
Follow this link:
06-03-2021 09:25 PM
Whenever you use a CALL statement that has to return the value that comes out of the call YIELD. If you are using this with MATCH statements then you can use RETURN.
Try without that RETURN statement. Sometimes it works!
06-03-2021 09:12 PM
Thank you. Let me try it.
06-04-2021 12:37 AM
@ameyasoft how do i do this for c and d in one go? here we can connect a and b with r1 only.
06-04-2021 09:44 AM
LOAD CSV WITH HEADERS FROM "file:///relations.csv" AS row
MERGE (a:Test {name: row.a})
MERGE (b:Test {name: row.b})
CALL apoc.create.relationship(a, row.R1,{}, b) YIELD rel
MERGE (c:Test {name: row.c})
CALL apoc.create.relationship(b, row.R2,{}, c) YIELD rel1
MERGE (d:Test {name: row.d})
CALL apoc.create.relationship(c, row.R3,{}, d) YIELD rel2
All the sessions of the conference are now available online