Neo4j加权交互

时间:2018-03-21 18:01:42

标签: neo4j cypher nodes edges

我有一个大的CSV文件,看起来像

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

我想在Neo4j上创建一个图表,显示Node1和2之间通过列权重加权的交互。

由于这篇文章How to create unique nodes and relationships by csv file imported in neo4j?

,我创建了互动

但我还没有重量

我尝试了以下

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);

但它不起作用...... 谢谢!

1 个答案:

答案 0 :(得分:1)

看起来你正在尝试为这段关系添加一个属性。试试这个:

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);