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.

Csv triples to neo4j graph

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?

1 ACCEPTED SOLUTION

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'

View solution in original post

1 REPLY 1

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'