Bulk Upload csv to Neo4j on windows

This blog post was originally intended only for data based philosophical discussions. However, given that I have not posted anything in many a years I decided to dilute it.

I had lot of problems bulk importing csv data in to neo4j. I have finally figured out how to do it.

neo4j is a graph db. I won't go in to details of what is a graph db or how to write cypher queries.
once you have downloaded neo4j from  here and installed neo4j you will see the neo4j desktop app.

Add a new graph. create a new graph give it a password. once the graph is created click on manage and go to the "Terminal" tab.






Now before we go ahead you need to prepare your csv files. your csv files should be split as node csv and relations svs. And the initial headings have to follow a syntax.
In your node csv the first column should be unique key and your first column heading should be
<your id>:ID(<your node name>)

In your relations csv you must have start and end nodes. (note that they can be different nodes eg. user and property.)
you can chose to ignore other columns in these csvs if they are not ignored they are captured as attributes. (see https://neo4j.com/developer/guide-import-csv/ for more details)

bin\neo4j-admin import --mode=csv --nodes:User=import\<your node csv> --relationships:FOLLOWS=import\<your relationship csv> --ignore-missing-nodes=true --multiline-fields=true

eg:
bin\neo4j-admin import --mode=csv --nodes:User=import\user.csv --relationships:FOLLOWS=import\User_FOLLOWS.csv --ignore-missing-nodes=true --multiline-fields=true

Note the only difference between windows and linux is / and \ . Most of the documentation you find online will be for linux. so when the document asks you to use "ls" use "dir" instead.

once you have run this command. be sure to hit the play button on top before you connect to the database. you can bulk import csv in to a neo4j db only once. It does not create transaction logs and it is meant for one time first upload only.

If you want to try this with a small file you can use the csvs in my Git page.
Download sample csvs place them in the correct import folder and run this command in the neo4j terminal.
bin\neo4j-admin import --mode=csv --nodes:Worker=import\id.csv --relationships:FOLLOWS=import\relations.csv --ignore-missing-nodes=true --multiline-fields=true

The full video is on youtube


Comments

Popular posts from this blog

Virus: Discussing macroscopic possibilities

Could Generative AI pose an existential threat to us?

Advantage; Homeloan