【发布时间】:2016-12-11 02:38:15
【问题描述】:
我有两张表事件和地点。
我已将它们下载到 csv 文件中。
我运行以下查询来创建节点:
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:////path/tb_location.csv" AS row
CREATE(:tb_location{ latitude: row.latitude,longitude: row.longitude,location_description:
row.location_description,community_area: row.community_area,block: row.block,district: row.district,ward: row.ward,x_coordinate: row.x_coordinate,y_coordinate: row.y_coordinate,id_city: row.id_city,composite_key: row.composite_key });
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:////path/tb_incident.csv" AS row
CREATE(:tb_incident{ id: row.id,primary_type: row.primary_type,domestic: row.domestic,date: row.date,description: row.description,arrest: row.arrest,beat: row.beat,year: row.year,updated_on: row.updated_on,latitude : row.latitude,longitude: row.longitude,case_number: row.case_number,composite_foreign_key: row.composite_foreign_key});
然后我在匹配属性上创建索引:
CREATE INDEX ON :tb_incident(composite_foreign_key);
CREATE INDEX ON :tb_location(composite_key);
然后我尝试建立关系:
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:////path/tb_incident.csv" AS row1
MATCH(tb_incident:tb_incident{composite_foreign_key: row1.composite_foreign_key})
LOAD CSV WITH HEADERS FROM "file:////path/tb_location.csv" AS row2
MATCH(tb_location:tb_location{composite_key: row2.composite_key})
WHERE tb_incident.composite_foreign_key = tb_location.composite_key
MERGE (tb_incident)-[:occured_at]->(tb_location);
但是,最后一个查询将一个事件链接到所有位置。 我是 cypher 的新手,我找不到我做错了什么。我打算仅将一个事件与一个位置联系起来。 如果您能帮我纠正这个不正确的查询,请提供帮助。
【问题讨论】: