在Neo4J中我试图想象一下从csv文件中获取的少量调用(下面的虚假数字样本):
A,B
1,4
1,5
1,2
2,7
2,9
2,11
3,15
我正在处理每一列(A,B),因为电话号码将是节点,并且它们之间存在呼叫(A到B)是关系
理想情况下,生成的图表应显示多个关系 节点(例如:值为1的节点将与其他节点建立三个连接,其中一个是节点2,值为2,另有三个连接,最后一个值为3的节点将具有连接但是是分开的)
我正在尝试的代码
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:blahblahblah.csv" AS row
CREATE (A:phone {number: row.A})
CREATE (B:phone {number: row.B})
WITH A as a MATCH (a)-[:CALLED*]-(m)
RETURN a,m
显然它产生了重复的节点,只有单一的关系,没有二级箭头..
我在这里做错了什么?
答案 0 :(得分:1)
这应该是最有效的:
create constraint on (p:phone) assert p.number is unique;
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:blahblahblah.csv" AS row
with distinct row.A as value
MERGE (:phone {number: value});
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:blahblahblah.csv" AS row
with distinct row.B as value
MERGE (:phone {number: value});
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:blahblahblah.csv" AS row
MATCH (A:phone {number: row.A})
MATCH (B:phone {number: row.B})
MERGE (A)-[r:CALLED]->(B)
ON CREATE SET r.count = 1
ON MATCH SET r.count = r.count + 1;
不确定您要查询的内容吗? E.g。
MATCH (a:phone)-[r:CALLED]->(b)
RETURN a, sum(r.count) as calls
ORDER BY calls DESC LIMIT 10;