我是neo4j和cypher的新手,如果需要改进我的问题,请告诉我,我将尝试使其更加有意义。
我有一个.csv格式的数据集,包含1000行。我已经在neo4j本地主机中使用cypher导入了该数据集。 fromacc
。这是样本数据集图像
列toacc
和timestamp
包含重复的值。我想绘制在边和节点中显示amount
和fromacc
的{{1}}和toacc
的连通图。
我已附上图表的图像:
我写的查询是:
LOAD CSV WITH HEADERS FROM "file:///datanew.csv"As row CREATE (demo:demo
{blockid:toInteger(row.id),blockhas:row.hash,txnid:row.txs,
frmacc:row.frmacc,toacc:row.toacc,amount:toInteger(row.amount)})
Create (p:demo{frm:demo.frmacc})-[r:transferred]- >
(q:demo{toa:demo.toacc}) return r
但是我只有一个节点重复连接到另一个节点。
任何人都可以帮助我在上图中获得所需的图形。预先感谢。
数据:
id hash time_stamp txs from to amount
0 hash1 1231006505 1 685031 97258 65536
1 hash2 1231469665 1 761055 97260 65536
2 hash3 1231469744 1 2039922 97261 1000000
3 hash4 1231470173 1 2271509 584573 3000000
4 hash5 1231470988 1 2271510 584574 3000000
5 hash6 1231471428 1 2271511 584577 3000000
6 hash7 1231471448 2 685031 16785 1000000
7 hash8 1231471478 1 685031 97258 677888
8 hash9 1231471498 2 97258 685031 567890
9 hash0 1231471444 1 97258 584577 100000
Here "from" and "to" represents nodes "A,B" in the the graph I plotted and attached
In the vertices amount,timestamp should be mentioned
答案 0 :(得分:1)
如果row.id
是节点之间关系的标识符,则对于每个row
,您首先需要创建一对节点,然后在它们之间创建关系,然后设置关系属性。使用merge
代替create
来每次都不创建新节点。例如:
UNWIND [{id:0,hash:"hash1",time_stamp:1231006505,txs:1,from:685031,to:97258,amount:65536},
{id:1,hash:"hash2",time_stamp:1231469665,txs:1,from:761055,to:97260,amount:65536},
{id:2,hash:"hash3",time_stamp:1231469744,txs:1,from:2039922,to:97261,amount:1000000},
{id:3,hash:"hash4",time_stamp:1231470173,txs:1,from:2271509,to:584573,amount:3000000},
{id:4,hash:"hash5",time_stamp:1231470988,txs:1,from:2271510,to:584574,amount:3000000},
{id:5,hash:"hash6",time_stamp:1231471428,txs:1,from:2271511,to:584577,amount:3000000},
{id:6,hash:"hash7",time_stamp:1231471448,txs:2,from:685031,to:16785,amount:1000000},
{id:7,hash:"hash8",time_stamp:1231471478,txs:1,from:685031,to:97258,amount:677888},
{id:8,hash:"hash9",time_stamp:1231471498,txs:2,from:97258,to:685031,amount:567890},
{id:9,hash:"hash0",time_stamp:1231471444,txs:1,from:97258,to:584577,amount:100000}] AS row
MERGE (F:demo {id: row.from})
MERGE (T:demo {id: row.to})
MERGE (F)-[r:transferred {id: row.id}]->(T)
SET r.hash = row.hash,
r.time_stamp = row.time_stamp,
r.txs = row.txs,
r.amout = row.amout
RETURN F, T, r