neo4j partial dump with cypher in java

2019-08-09 20:09发布

问题:

Yesterday i asked a question but it was unclear, so i created a new one with really better explanations to find the answer i need :).

So, in my Java Application, i need to do a neo4j copy System, here is an example:

       A      <--- this is a project 
      / \     <--- With relationships
     B   C    <--- and subnodes + Labels
    / \ / \   <--- with a depth unknown
   .........

I need to do a copy of this in my database, with another id, like this:

       A                 A1    
      / \               /  \     
     B   C             B1  C1  
    / \ / \           / \  / \  
   .........         ..........   

In neo4j shell, i can simply use dump from A to n to return a cypher statement that i can copy and paste to neo4j web interface to create my copy.

But in fact, i'm in an application with java, so i need to find how to do the same thing, but with java (i'm using VAADIN framework + JDK7 + Neo4j 2.1.4).

I tried to use Neo4j-shell in java but never found how to get the reply from dump command (the cypher sentence) so i'm stuck now, and asking on stack overflow to get help :).

Have a nice day

回答1:

Dump is a shell command, in theory you could instantiate and run it yourself.

It uses the SubgraphExporter from the Cypher module, Neo4j is OSS you can find it on GitHub

In general it should be easier for you to run a cypher query against the database yourself and then with the results recreate the data you're interested in.

Something like this should help you:

https://github.com/neo4j-contrib/developer-resources/blob/gh-pages/examples/java/jdbc/src/main/java/example/jdbc/movies/MovieService.java#L58