简体   繁体   English

从单个csv文件在Neo4j中创建关系

[英]Creating relationship in Neo4j from a single csv file

I am trying to load a single csv into a Neo4j DB. 我正在尝试将一个csv加载到Neo4j DB中。 I have followed this guideline but still can't understand why is not working for me. 遵循了该指南,但仍然不明白为什么对我不起作用。

I can create the nodes correctly (its attributes are all the columns but one) and I want to build a relationship between all the nodes with the only attribute left that wasn't added to the node. 我可以正确地创建节点(它的属性是除一列以外的所有列),并且我想在所有节点之间建立一个关系,并保留唯一未添加到节点的属性。

My data in file.csv looks like: 我在file.csv数据如下所示:

Column,instaGramId,imageDateCreated,imageTagCount,imageFilter,googleLabel_list 0,1165524631240624607_638926073,1453161384,7,Normal,"[cartoon, comics, artwork]" Column,instaGramId,imageDateCreated,imageTagCount,imageFilter,googleLabel_list 0,1165524631240624607_638926073,1453161384,7,Normal,“ [[卡通,漫画,艺术品]”
... ...

I'm following these steps: 我正在按照以下步骤操作:

Step 1: creating nodes this is working correctly 第1步:创建 正常运行的 节点

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS row 
CREATE (:Post {instaGramId: row.instaGramId,
    imageDateCreated: toInt(row.imageDateCreated),
    imageTagCount: row.imageTagCount,
    imageFilter: row.imageFilter});

Only attribute left is googleLabel_list which needs to be a in a different node 剩下的唯一属性是googleLabel_list ,该属性必须位于其他节点中

Step 2: create an Index this is working correctly too, I guess 第2步:创建一个索引, 它也可以正常工作

CREATE INDEX ON :Post(instaGramId);

Step 3: create relationships this is not working correctly 步骤3:建立关系 这无法正常工作

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS row
MATCH (post:Post {id: row.instaGramId})
MATCH (objects:Post {id: row.googleLabel_list})
MERGE (post)-[:CONTAINS_OBJECTS]->(objects);

The following clause will probably never match anything (and therefore no relationships will ever be created): 以下子句可能永远不会匹配任何内容(因此将不会创建任何关系):

MATCH (objects:Post {id: row.googleLabel_list})

This is because your existing POST nodes have id values (eg, "1165524631240624607_638926073" -- which come from row.instaGramId ) that probably look nothing like your row.googleLabel_list values (eg, "[cartoon, comics, artwork]"). 这是因为您现有的POST节点具有id值(例如,“ 1165524631240624607_638926073”,该值来自row.instaGramId ),看上去可能与您的row.googleLabel_list值(例如,“ [卡通,漫画,艺术品]”)完全不同。

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

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