One can use LOAD CSV
(with Aura, the file must be publicly hosted HTTP/HTTPS or FTP) to perform a bulk update to existing nodes and create new nodes, as follows.
If we have a .csv called Movies.csv
and its content is:
code,wysiwyg-indent3
code,wysiwyg-indent3
101,The Matrix,463420706
102,The Matrix Reloaded,738576929
103,The Matrix Revolutions,427289109
104,A Few Good Men,24234017
The current graph includes nodes with a label Movie
for the 1st three movies listed, then the following LOAD CSV
Cypher statement will result in updating the TotalRevenue property for the three existing Movie
nodes and creating a new node for the fourth movie, namely A Few Good Men
:
LOAD CSV FROM "https://raw.githubusercontent.com/username/Movies.csv" AS csvLine
MERGE (n:Movie {id:csvLine[0]})
ON CREATE SET n.id=csvLine[0],n.name=csvLine[1], n.TotalRevenue = csvLine[2]
ON MATCH SET n.TotalRevenue = csvLine[2]
Running the above Cypher the first time will result in:
Added 1 label, created 1 node, set 7 properties
Subsequent re-runs of the same LOAD CSV
will result in:
Set 4 properties
Loading CSVs from URLs
You can instruct LOAD CSV to retrieve files from FTP, HTTP, or HTTPS servers.
One particularly easy way to accomplish this is to place your CSV files in an Amazon AWS S3 Bucket and then make that Bucket into a static HTTP server. Amazon has some good documentation on this.
For examples of importing CSV from some common public-hosted locations(Github, Website, Google Sheet etc.) into a Cloud-hosted Neo4j Instance, please refer to the 'Neo4j Aura and Neo4j Sandbox' section of our Importing CSV Files article.
Comments
0 comments
Please sign in to leave a comment.