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.
There are a number of options:
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.
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
you can export cypher results to CSV (e.g. from the browser) and import it again using for instance LOAD CSV
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With