如何将分割节点连接到另一个节点?

时间:2016-04-11 14:09:56

标签: neo4j cypher graph-databases

我目前正在尝试使用movie-id,director和actor在我的neo4j数据库中导入csv文件。 csv看起来像这样:

 |id|    directors   |           actors                |
 |33|Steven Spielberg|Tom Hanks; Brad Pitt; Tim Allen  |
 |34|John Lasseter   |Ryan Goslin; Brad Pitt; Tom Hardy|

我的问题:我能够将演员分成独立的节点,但他们并没有连接到他们演出的MovieID。

在为影片ID和导演/演员名称设置唯一约束后,我的Cypherquery看起来像这样:

 LOAD CSV WITH HEADERS FROM  
 'file:///C:/Users/Jens/Documents/SeminarDB/kleinefilmDB.csv' AS line
 CREATE (movie:Movie {id: TOINT(line.id)}) 
 MERGE (director:Director {name: line.director} )
 FOREACH (n IN SPLIT(line.actors, ";")| MERGE (actor:Actor {name: n}))

 CREATE (actor)-[:ACTED_IN]->(movie)
 CREATE (director)-[:DIRECTED]->(movie)

1 个答案:

答案 0 :(得分:0)

您需要在FOREACH中创建关系。

LOAD CSV WITH HEADERS FROM  
'file:///C:/Users/Jens/Documents/SeminarDB/kleinefilmDB.csv' AS line
CREATE (movie:Movie {id: TOINT(line.id)}) 
MERGE  (director:Director {name: line.director} )
CREATE (director)-[:DIRECTED]->(movie)   
FOREACH (n IN SPLIT(line.actors, ";")| 
         MERGE (actor:Actor {name: n})
         CREATE (actor)-[:ACTED_IN]->(movie)
        )