我尝试将一些RDB记录移入Neo4j。在MySQL上有一个关系表。我想将其更改为Neo4j上的关系。
我创建了两个节点,如下所示。
LOAD CSV WITH HEADERS
FROM 'file:///transactions.csv' AS line
CREATE (:Tran {
key_from: line.key
});
LOAD CSV WITH HEADERS
FROM 'file:///master.csv' AS line
CREATE (:Master {
key_to: line.key
, value: line.value
});
导入非常快。 Tran
有20,000条记录。 Master
有270,000条记录。然后我尝试导入关系csv文件。
我尝试了两个查询。但是,他们两个都没有完成。有5,000个关系,但是有些关系应该匹配,其余的将不匹配。
Try1:
LOAD CSV WITH HEADERS
FROM 'file:///relation.csv' AS line
OPTIONAL MATCH (t:Tran { key_from: line.key_from })
OPTIONAL MATCH (m:Master { key_to: line.key_to })
CREATE (t)-[r:CONV]->(m);
Try2:
LOAD CSV WITH HEADERS
FROM 'file:///relation.csv' AS line
WITH line.key_from AS key_from,
line.key_to AS key_to
MERGE (t:Tran { key_from: key_from })
MERGE (m:Master { key_to: key_to })
MERGE (t)-[r:CONV]->(m);
您能告诉我最佳实践吗?