1
votes

Here is my scenario:

  • a single application generates a directed graph - it's relatively well balanced, having about 10 levels, 20k nodes and 30k relationships,

  • this graph must be immediately stored within neo4j, so that this app can make some Cypher queries and move on - it's important to execute this step as fast as possible,

  • at the same time this graph must be stored in some way (Cypher query? CSV? something custom?) so that another application will fetch a few thousands of those graphs at some point, add all of them to neo4j and will execute Cypher queries on them - time is not a critical factor for this step.


I thought I will be able to create a single Cypher query that will insert the whole graph at once. That would match my scenario pretty well, as I would be able to build my graph, represent it as a Cypher query, execute locally to do what the app needs to do on a single graph, and then store that query somewhere for future use. Unfortunately, it only works for small graphs.

When I call a query like the one below using neo4j-shell or from within Java code - it breaks on any graph which has a few hundreds of nodes/relationships:

CREATE (h1:Node:_Node {...}), (h2:Node:_Node {...}), (h3:Node:_Node {...}), ...,
       (h1)-[:REL1]->(h2), (h1)-[:REL2]->(h3), (h2)-[:REL2]->(h3), ...

I've tried multiple other things, but nothing works as expected.
Please advise what is the best approach here.

2

2 Answers

1
votes

Store your data into couple of csv files (nodes, relationships, ..) and use LOAD CSV cypher clause.

This is supposed to be very fast, you should be able to load data and query your graph in matter of seconds.

You can then distribute the csv file to another machine and load it the same way.