I am considering replacing a MySQL database with a neo4j database. I am a complete beginner with neo4j and would like to know how to go about doing a batch insert of my current MySQL data into the neo4j database so i can experiment and begin to learn about neo4j.
the relational database consists of 4 tables: Person
, Organism
, Story
, Links
.
Links describes relationships between rows in the other 3 tables.
Links
:
ID, FromTable, FromID, ToTable, ToID, LinkType
Person
:
ID, property_2, property_1, etc ...
Organism
:
ID, property_A, property_B, etc ....
Story
:
ID, property_x, property_y
each ID field is an auto incrementing integer starting from 1 for each table
In case it is not obvious, a link between say person with ID 3 and a story with ID 42 would have a row in the Links table ID=autoincrement, FromTable=Person, FromID=3, ToTable=Story, ToID=42. Even though I am using the terms 'from' and 'to' the actual links are not really 'directed' in practice.
I have looked at Michael Hunger's batch-import but that seems to only work with a single table of nodes and one table of relationships, whereas I am looking to import three different types of nodes and one list of relationships between them.
I have got neo4j up and running, Any advice to get me started would be greatly appreciated.
I am not familiar with Java, though I do use Python and bash shell scripts. After initial import, I will be using the RESTful interface with Javascript.
Based on advice in the git repo. Using Michael Hunger's batch-import it is possible to import multiple node types from the one .csv file. To quote Michael:
So the general approach i used was:
combine all the nodes tables into a new table called
nodes
:nodes
with an auto incrementingnewID
field and atype
field. the type field will record what table the node data came fromINSERT INTO nodes
the values fromPerson
, thenOrganism
, thenStory
, in addition to setting thetype
field to person, organism, or story. Leave any unrelated fields blank.in another new table
rels
add the newly creatednewID
indexes to theLinks
table based on a sqlJOIN
:Then export these two new tables
nodes
andrels
as Tab seperated .csv files, and use them with batch-import:As you say that you are happy working with python and shell scripts, you may also want to have a look at the command line tools which come with py2neo, in particular
geoff
. This uses a flat file format I put together for holding graph data so in your instance, you would need to build a flat file from your source data and insert this into your graph database.The file format and server plugin are documented here and the py2neo module for the client application is here.
If anything is missing from the docs or you want more information about this then feel free to drop me an email
Nigel