Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j export & import data

Is there a good way to use the Neo4j Java API to migrate some data from one database to another? My use case is to load a few thousand nodes into a temporary database, do a bunch of transformations, then export the results to the main database and delete the temporary one.

I don't want to clobber the data in the destination db, this is an additive process. I see lots of people on the internet (e.g. here) saying "just copy the data directory to the new location", but of course that would clobber the destination.

UPDATE - I experimented with neo4j-shell -path tmpDir -c "DUMP MATCH n RETURN n;" | neo4j-shell -path dbDir -file -, but it's really horribly slow. Generating the output seems fast enough but slurping it back in is glacial, even on a fresh empty database.

like image 369
Ken Williams Avatar asked Jan 30 '15 23:01

Ken Williams


1 Answers

There are a number of options:

  1. You can just open two neo4j databases in your java copy and use the Java API to transfer nodes and relationships from one to another.

  2. On low level for initial seeding you can do the same with batch-inserter-apis, like I did here: https://github.com/jexp/store-utils/tree/21

  3. you can export cypher results to CSV (e.g. from the browser) and import it again using for instance LOAD CSV

  4. You can use neo4j-shell-tools for some of those import-export tasks e.g. exporting to GraphML or CSV and importing it back again

like image 190
Michael Hunger Avatar answered Oct 01 '22 17:10

Michael Hunger