+1 vote
in Databases by (60.0k points)
I want to load relationships to Neo4j from a file. The issue is that there are different types of relationships between two nodes in the file. How can I crate relationships dynamically in Neo4j using Cypher query?

1 Answer

+1 vote
by (77.0k points)
selected by
 
Best answer

You can use the apoc.create.relationship procedure from the APOC library to create dynamic relationships.

Here is an example to show how to use this procedure:

LOAD CSV WITH HEADERS FROM "file:///edges.tsv" AS row FIELDTERMINATOR '\t'

MATCH (c1: node1 {id: trim(row.source)}), (c2: node2 {id: trim(row.target)})

CALL apoc.create.relationship(c1, row.relation, c2) YIELD rel

return count(rel);

In the above example, relationships are dynamically created between nodes node1 and node2 using the relation column in the edges.tsv file. 

Related questions


...