Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-02-2019 02:38 AM
I have a csv file having 5 columns. I want to model a graph in the following way:
First column-> node
Second column -> label of the node from first column
Fourth column-> node
Fifth column -> label of the node from fourth column
Third column -> relation between node from first column and fourth column.
how can I write a cypher query to do this?
Solved! Go to Solution.
02-02-2019 03:04 AM
You need APOC in order to import dynamic labels.
I will assume that the third column contains the relationship type.
LOAD CSV FROM "file:///your_file.csv" as row
CALL apoc.merge.node([row[1], {id:row[0]}, {})
YIELD node as startNode
CALL apoc.merge.node([row[4], {id:row[3]}, {})
YIELD node as endtNode
CALL apoc.create.relationship(startNode, row[2], {}, {}, endNode) yield rel
RETURN distinct 'done'
02-02-2019 03:04 AM
You need APOC in order to import dynamic labels.
I will assume that the third column contains the relationship type.
LOAD CSV FROM "file:///your_file.csv" as row
CALL apoc.merge.node([row[1], {id:row[0]}, {})
YIELD node as startNode
CALL apoc.merge.node([row[4], {id:row[3]}, {})
YIELD node as endtNode
CALL apoc.create.relationship(startNode, row[2], {}, {}, endNode) yield rel
RETURN distinct 'done'
All the sessions of the conference are now available online