Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-16-2022 11:34 PM
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
Solved! Go to Solution.
01-17-2022 01:11 AM
Try that:
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;
01-17-2022 12:22 AM
Hello @11li and welcome to the Neo4j community
Can you share the CSV files to create nodes and relationships?
Regards,
Cobra
01-17-2022 12:37 AM
Hi!
Followings are part of my files.
csv can't upload.
trackCheckContent.csv
checkAppliance.csv
Thank you!
Regards,
Yiyi
01-17-2022 12:38 AM
You can upload files here but you must replace the extension of the files by .txt.
01-17-2022 12:39 AM
ok! thanks!
checkAppliance.txt (417 Bytes)
risk_appliance.txt (860 Bytes)
trackCheckContent.txt (10.4 KB)
01-17-2022 12:40 AM
Thank you, I'm gonna try to find your issue now
01-17-2022 12:54 AM
First, you must create UNIQUE CONSTRAINTS
:
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).
01-17-2022 01:05 AM
01-17-2022 01:11 AM
Try that:
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;
01-17-2022 01:19 AM
It worked!!! Thank you very much !
I still got one question that why can't I change the caption of this kind of node.
01-17-2022 01:23 AM
No problem, what do you mean by the caption?
01-17-2022 02:12 AM
01-17-2022 02:18 AM
Oh, yes, you can, there is an arrow on the right on the same line, just click on it and you will see the properties.
01-17-2022 02:29 AM
oh!! I see!!!
thank you very much !!!!!
03-30-2022 07:59 PM
Sorry to bother you again😅
Could you please tell me how can I delete all the data?
03-30-2022 08:05 PM
I checked your other answers and try drop constraint
03-30-2022 11:19 PM
If you want to clean everything:
CREATE OR REPLACE DATABASE neo4j
04-01-2022 08:03 PM
Sorry for the late reply. But it didn't work
04-02-2022 12:53 AM
Version: | 4.2.3 |
---|---|
Edition: | Community |
Name: | neo4j |
Databases: | :dbs |
Information: | :sysinfo |
Query List: | :queries |
04-02-2022 12:54 AM
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.
04-02-2022 01:24 AM
Thank you!
So I can't just write a line to delete all peoperty keys, right?
04-02-2022 01:40 AM
Yeah that's right, there is no alternative option right now:)
04-02-2022 01:58 AM
Documentation only support enterprise edition...
and I don't know which part of the folder can be deleted...
Is there a documentation support Community version?
04-02-2022 04:34 AM
Delete the neo4j folder in the databases folder and it should be good but you will have to recreate a database after.
04-03-2022 07:30 AM
04-03-2022 12:22 PM
Did you shutdown the server before to delete the folder and did you restart it after?
You should open another topic for this problem.
04-04-2022 03:49 AM
Thank you!
Yes, I did shutdown the server before I delete the neo4j folder and restart it.
But it turns out to be the picture I sent. So I delete the whole folder and download a new community version
Now it's ok.
I will open another topic when I have to create a database after.
All the sessions of the conference are now available online