Hi, I'm new to neo4j and Cypher language.
I have created 2 kinds of nodes using cypher:
load csv with headers from 'file:///trackCheckContent.csv' as line
create(:TrackCheckContent{risk:line.risk,risk_id:line.risk_id,info_source:line.source,url:line.URL,checkFrequency:line.checkFrequency})
load csv with headers from 'file:///checkAppliance.csv' as line
create(:checkAppliance{appliance:line.check_appliance,appliance_id:line.appliance_id})
Now I want to create relationship between these 2 kinds of node.
I have a csv file be like:
then I use cypher:
LOAD CSV WITH HEADERS FROM "file:///risk_appliance.csv" AS row
match (from:TrackCheckContent{id:row.risk_id})
match (to:checkAppliance {id:row.appliance_id})
merge (from)-[r:use]->(to)
It turns out to be (no changes, no records)
And if I try this:
LOAD CSV WITH HEADERS FROM "file:///risk_appliance.csv" AS row
match (from:TrackCheckContent{id:row.risk_id}),(to:checkAppliance {id:row.appliance_id})
merge (from)-[r:use]->(to)
I will get This query builds a cartesian product between disconnected patterns.
I just want to create relationships between these 2 kinds of node. plz help
CREATE CONSTRAINT constraint_track_check_content IF NOT EXISTS FOR (n:TrackCheckContent) REQUIRE n.risk_id IS UNIQUE;
CREATE CONSTRAINT constraint_check_appliance IF NOT EXISTS FOR (n:CheckAppliance) REQUIRE n.appliance_id IS UNIQUE;
Then you load nodes:
LOAD CSV WITH HEADERS FROm 'file:///TrackCheckContent.csv' AS line
MERGE (n:TrackCheckContent {risk_id: line.risk_id}) SET n += line
LOAD CSV WITH HEADERS FROm 'file:///CheckAppliance.csv' AS line
MERGE (n:CheckAppliance {appliance_id: line.appliance_id}) SET n += line
Finally, you load relationships:
LOAD CSV WITH HEADERS FROm 'file:///RiskAppliance.csv' AS line
MATCH (a:TrackCheckContent {risk_id: line.risk_id})
MATCH (b:CheckAppliance {appliance_id: line.appliance_id})
MERGE (a)-[:USE]->(b)
Everything worked on my end and I used the latest version of Neo4j (4.4.3).
CREATE CONSTRAINT constraint_track_check_content IF NOT EXISTS ON (n:TrackCheckContent) ASSERT n.risk_id IS UNIQUE;
CREATE CONSTRAINT constraint_check_appliance IF NOT EXISTS ON (n:CheckAppliance) ASSERT n.appliance_id IS UNIQUE;
Ah, you are on Community version, that's why it's not working, you can check the documentation here.
For Community version, you will have to drop the folder of the database then recreate a database.