[英]Unable to create relationships importing a csv in Neo4j
I am unable to create relationships importing .csv files in Neo4j 我无法在Neo4j中创建导入.csv文件的关系
The nodes I have are for Medical Providers and Medical Conditions 我拥有的节点是医疗服务提供者和医疗条件
The relationship is Provider-[TREATS]->Condition 这种关系是提供者 - [条约] - >条件
Here is a subset of my providers csv: 这是我的提供者csv的一个子集:
Provider,ProviderID,Office,Street,City,State,Zip,Phone
Dr. Mxxxxi MD,1,The xxx Hospital,1xxx xxx Hwy,Ft Wright,KY,4xxxxx,(xxx) xxx-3304
Here is a subset of my conditions csv: 这是我的条件csv的一个子集:
condition,conditionID
Acute Leukemia,1
Acute Lymphoid Leukemia,2
Acute Myeloid Leukemia,3
Adrenal Gland Cancer,4
....
Here is a subset of my relations csv: 这是我的关系csv的一个子集:
ProviderID,ConditionID
1,1
1,2
1,3
1,4
1,5
1,6
1,7
1,8
1,9
...
Here are the import/create statements: 以下是import / create语句:
// Create providers
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///providers.csv" AS row
CREATE (:Provider {provider: row.Provider, providerID: row.ProviderID, officeName: row.OfficeName, street:row.Street, city:row.City, state:row.State, zip:row.Zip, phone: row.Phone});
Added 1 label, created 1 node, set 7 properties, statement completed in 283 ms 添加了1个标签,创建了1个节点,设置了7个属性,语句在283毫秒内完成
// Create conditions
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///conditions.csv" AS row
CREATE (:Condition {Condition: row.condition, ConditionID:
row.conditionID});
Added 100 labels, created 100 nodes, set 200 properties, statement completed in 262 ms. 添加了100个标签,创建了100个节点,设置了200个属性,语句在262毫秒内完成。
I created indexes: 我创建了索引:
CREATE INDEX ON :Provider(providerID);
CREATE INDEX ON :Condition(conditionID);
This is the import/create relationship statement and result: 这是导入/创建关系语句和结果:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///ProviderConditionsTreated.csv" AS row
MATCH (p:Provider { providerID: row.ProviderID})
WITH p
MATCH (c:Condition { conditionID: p.ConditionID})
CREATE (p)-[t:TREATS]->(c);
(no changes, no records) (没有变化,没有记录)
I have also tried this with no records 我也试过这个没有记录
MATCH (p:Provider { providerID: row.ProviderID})
MATCH (c:Condition { conditionID: row.ConditionID})
CREATE (p)-[t:TREATS]->(c);
(no changes, no records) (没有变化,没有记录)
I see two issues with your import query: 我看到导入查询存在两个问题:
The Cypher language is case-sensitive for labels, types and property names. Cypher语言对标签,类型和属性名称区分大小写 。 In your providers.csv file, the ProviderID
attribute starts with an uppercase character, but in the conditions.csv file, the conditionID
attribute starts with a lowercase one. 在providers.csv文件中, ProviderID
属性以大写字符开头,但在conditions.csv文件中, conditionID
属性以小写字母开头。 While loading them with the LOAD CSV
commands, these are actually changed to providerId
and ConditionId
. 使用LOAD CSV
命令加载它们时,这些命令实际上已更改为providerId
和ConditionId
。 It's best to keep these consistent both for the CSV files and for the vertex properties. 最好保持CSV文件和顶点属性的一致性。
You should not use WITH p
as you will no longer be able to access the row
variable. 您不应该使用WITH p
因为您将无法再访问row
变量。 This is fixed in your last query. 这已在您上次查询中修复。 However, even that can be simplified by using a single MATCH
clause. 但是,即使这样也可以通过使用单个MATCH
子句来简化。
In conclusion, the following query worked for me: 总之,以下查询对我有用:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///relations.csv" AS row
MATCH
(p:Provider { providerID: row.ProviderID}),
(c:Condition { ConditionID: row.ConditionID})
CREATE (p)-[t:TREATS]->(c);
Created 4 relationships, completed after 110 ms. 创建了4个关系,在110毫秒后完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.