Search code examples
neo4jcyphernodesedges

Neo4j Weighted Interactions


I have a large CSV file which looks like

Node1    Node2    Weight
1         2         10 
2         3         15
1         3         5
3         10        20
etc...

I would like to create a graph on Neo4j that show the interactions between the Node1 and 2 Weighted by the column Weight.

I created the interactions thanks to this post How to create unique nodes and relationships by csv file imported in neo4j?

But I don't have the weights yet

I tried the following

USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///ewqrwqsa.csv" AS line
MERGE (n:A {number : line.Node1})
WITH line, n
MERGE (m:B {ID : line.Node2})
WITH line, m, n 
MERGE (l:W {weight : toInteger(line.Weight)})
WITH l,m,n
MERGE (n)-[:Related(l)]->(m);

But it doesn't work... Thanks !


Solution

  • Looks like you're trying to add a property to the relationship. Try this:

    USING PERIODIC COMMIT 500
    LOAD CSV WITH HEADERS FROM "file:///ewqrwqsa.csv" AS line
    MERGE (n:A {number : line.Node1})
    MERGE (m:B {ID : line.Node2})
    MERGE (n)-[r:Related]->(m)
    SET r.weight = toInteger(line.Weight);