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.

How to Create Relationship between two Different Column in Neo4j

I am trying to initiate a relationship between two columns in Neo4j . my dataset is a CSV file with two-column refers to Co-Authorship and I want to Construct a Network of it. I already load the data, return them and match them.
Loading
load csv from 'file:///conet1.csv' as rec
Return
create (:Guys {source: rec[0], target: rec[1]})
now I need to Construct the Collaboration Network of data by making a relationship between source and target columns . What do you propose for the purpose?

2 REPLIES 2

ameyasoft
Graph Maven

Create two different nodes:
MERGE (g:Guys {name: "Guys"})
MERGE (s:Source {val: rec[0]})
MERGE (t:Target {val: rec[1]})
MERGE (g)-[:SOURCE]->(s)
MERGE (s)-[:TARGET]->(t)

What do source and target represent? Is this some kind of id? And do these need to be separate properties of a node, or is this supposed to refer to the same property, but a different context (as in, you want to find a :Guys node by id and it will be source, and then you want to find another :Guys node by id and it will be the target).

If that's the case, then just use a single property, do two passes through the CSV to create the nodes (so you would have all your :Guys nodes created), then do a third pass that will MATCH your source and target by id (driven by the source and target columns in your CSV) and create the relationship between them.