我对 Neo4j 世界很陌生,所以如果这是一个微不足道的问题,请原谅我。我有 2 个表已使用 LOAD CSV 加载到数据库中
艺术家:
artist_name,artist_id
"Bob","abc"
"Jack","def"
"James","ghi"
"Someone","jkl"
"John","mno"
代理列表:
"Agency"
"A"
"B"
"C"
"D"
最后,我有一张中间表,上面有艺术家和代表他们的机构。
艺术家机构:
artist_name,artist_id,agency
"Bob","abc", "A"
"Bob","abc", "B"
"Jack","def", "C"
"James","ghi", "C"
"Someone","jkl","B"
"Someone","jkl", "C"
"John","mno", "D"
请注意,一些艺术家可能是多个机构的一部分(这就是我没有在艺术家表中包含机构变量的原因)
我试图获得四个基于 :REPRESENTS 关系连接到每个艺术家的代理节点。基本上是这样的:
(agency:Agency) - [:REPRESENTS] -> (artist:Artist)
我试过的代码是:
LOAD CSV WITH HEADERS FROM "file:///agency_list.csv" as agencies
CREATE (agency:Agency {agency: agencies.Agency})
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///artists.csv" as artists
CREATE (artist:Artist {artist: artists.artist_name, artist_id: artists.artist_id})
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///artist_agencies.csv" as line
CREATE (ag:Agency) - [:REPRESENTS] -> (ar:Artist {track_artist_uri:line.track_artist_uri})
到目前为止,我得到了这个,每个蓝色节点都是一个机构名称的副本。而不是只有一个代理节点通过 :REPRESENTS 关系连接到所有艺术家。结果
我想我的问题是我不知道如何通过这个中间的artist_agencies 表将艺术家表与agent_list 表联系起来。有没有更好的方法来做到这一点,还是我走在正确的轨道上?
谢谢!乔伊