简体   繁体   English

在neo4j中添加关系

[英]Adding relationship in neo4j

i have loaded the below mailer.csv file to neo4j using the below command and am able to see all the 10 nodes .我已使用以下命令将以下 mailer.csv 文件加载到 neo4j,并且能够看到所有 10 个节点。

CSV: CSV:

SENDER|RECEIVER|SENDDATE
Chris|Dean|2016-01-03
Brian|Chris|2016-01-02
Mark|Noah|2016-01-09
George|Henry|2016-01-05
Albert|Brian|2016-01-01
Thomas|Sean|2016-01-07
Sean|Mark|2016-01-08
Edgar|George|2016-01-04
Noah|Olivia|2016-01-10
Henry|Thomas|2016-01-06

Command:命令:

USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:///C:\\Users\\Abacus\\mailer.csv" AS row
FIELDTERMINATOR '|'
CREATE (:Mailer {Sender: row.SENDER, Receiver: row.RECEIVER,Senddate:row.SENDDATE});


//select all nodes
MATCH (n:Mailer)
RETURN n;

//count of nodes

MATCH (n:Mailer)
RETURN count(*)

am trying to create the below relationship between senders and receivers to see the trail of mails我正在尝试在发件人和收件人之间创建以下关系以查看邮件的踪迹

//create relationship
MATCH (n:Mailer)
CREATE (Sender)-[r:SENT_TO]->(Receiver);

But am unable to see the graphs in the below manner.但是我无法以以下方式查看图表。 Could you please help能否请你帮忙

send to     send to     send to

Albert------------Brian---------Chris-------------Dean艾伯特------------布莱恩------------克里斯------------迪恩

    send to         send to       send to       send to        send to     send to     send to

Edgar-------------George-------Henry--------------Thomas-----------Sean--------Mark-------Noah----------Olivia埃德加-------------乔治--亨利--------------托马斯------------肖恩--------马克-------诺亚-------奥利维亚

Something like this should work.像这样的事情应该有效。 The sender and receiver are both turned into Person nodes, and each person's node is created just once.发送者和接收者都变成了Person节点,每个人的节点只创建一次。

MATCH (n:Mailer)
MERGE (p1:Person {name: n.Sender})
MERGE (p2:Person {name: n.Receiver})
CREATE (p1)-[r:SENT_TO {date:n.Senddate}]->(p2);
RETURN p1, r, p2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM