本文介绍了如何从neo4j中的csv文件导入相同标签的节点之间的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将两个单独的csv文件导入到neo4j数据库中。第一个文件包含我要导入的所有节点。信息分类如下:

I have two separate csv files that I need to import into my neo4j database. The first file contains all the nodes that I wish to import. The information is classified as follows:

                             id, Name

                              1, Earth science

要导入它,我成功使用了以下代码:

To import it, I successfully used the following code:

创建(:学科{id:toInt(line.id),名称:line.Name})

CREATE (:Discipline { id: toInt(line.id), name: line.Name})

现在,我想导入我的关系文件并创建我刚导入的节点之间的所有关系。 Relationship.csv文件中的信息分类如下:

Now, I want to import my relationship file and create all the relationship between the nodes I just imported. The information in the relationship.csv file is classified as follows:

                 RelationshipID, parentID, relationship_type, childID

                              1, 2, IS_A_PARENT_DISCIPLINE_OF, 5

要导入该文件,我使用了以下代码,但未成功:

To import it, I used the following code, without success :

匹配(DParent:Discipline {id:toInt(csvLine.parentID)}),(DChild:Discipline {id:toInt(csvLine.childID)})

MATCH (DParent:Discipline { id: toInt(csvLine.parentID)}),(DChild:Discipline { id: toInt(csvLine.childID)})

创建(DParent)-[:IS_A_PARENT_DISCIPLINE_OF {id:toInt(csvLine.RelationshipID)}]->(DChild)

CREATE (DParent)-[:IS_A_PARENT_DISCIPLINE_OF { id:toInt(csvLine.RelationshipID) } ]->(DChild)

注意:结果不显示任何错误,它只返回任何更改,没有行。

Note: The result doesn't show any errors, it just returned no changes, no rows.

请参见下面的链接,以获取有关该主题的其他文档。我还没有找到描述如何导入csv文件以便在相同Label的节点之间创建关系的文档。

Please see the links below for other documentations I found regarding the subject; I have not found any documentation describing how to import csv files in order to create relationships between nodes of the same Label.

推荐答案

以下是导入的内容您需要在neo4j-shell中创建并运行.cypher文件才能导入数据...

The following is the content of the import.cypher file that you need to create and run in the neo4j-shell to import the data...

重要的是,在匹配并尝试创建关系时,您需要使用MERGE命令

Important thing is when matching and trying to create relationships you need to use the MERGE command

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:data/node.csv" AS row
CREATE (:Discipline{disciplineId: toInt(row.id), name: row.Name});

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:data/rels.csv" AS row
MATCH (parent:Discipline{disciplineId: toInt(row.parentID)})
MATCH (child:Discipline {disciplineId: toInt(row.childID)})
MERGE (parent)-[:IS_PARENT_DISCIPLINE_OF]->(child);

这篇关于如何从neo4j中的csv文件导入相同标签的节点之间的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:42