Importing Relationship from CSV file


(Joe) #1

Hi, I'm new to neo4j and Cypher language. I've 3 tables and I'm trying to mass import their relationship.

Table 1 ( Author_ID | Author_Name | (Other properties) )
Table 2 (Paper_ID | Paper_Name | (Other properties))
Table 3 (Subject | Relation | Object)

I've manage to import table 1 and 2 over to neo4j with their respective properties and created thousands of nodes. May I ask how do I create their relationship using the data from table 3?

An example of my table 3 could be :
(Author_1 | wrote | Paper_1) or (Author_2 | Influenced | Author_3) or (Author_4| gets_cited_by | Paper_5), basically a long table of subject, relation, object with the subject referencing from Author_ID of table 1 and object referencing from Author_ID or Paper_ID of table 1/2.

I thought I could do something like this but realized that it doesn't take any reference from my existing nodes

LOAD CSV WITH HEADERS FROM 'relation.csv' AS line
CREATE (line.Subject)-[:line.Verb]->(line.Object)

(Stefan Armbruster) #2

In plain cypher you cannot have dynamic relationship types. However you can use call apoc.create.relationship(from, type, properties, to) yield rel instead. See APOC docs for details.