Bulk creation of relationships on existing nodes

Hi all,

I'm struggling for days on a strategy for bulk creation of relationships on existing nodes. I have a set of nodes already in Neo4j and an external base of relationships in a dict (or dataframe):

{('A', 'B'): {
  'sim1': 0.2943630213889271,
  'sim2': 0.4710701248095422,
  'sim3': 0.5337783469032883,
  'composed_sim': 0.45043293483711544},

That is, the key is a tuple of the nodes to be related and sim1, sim2,..., are properties for this relation.

I can merge this relationships flawlessly iterating in a for loop with apoc.merge.relationship, however, for millions of relationships, this strategy is unfeasible.

I've been reading about apoc.periodic.iterate() but I got confused about how this kind of external data is supposed to be loaded (my Neo4j instance runs on a remote container and I'm using py2neo to interact with it) and how to build the mappings for the batch operation.

Could someone please clarify how can I use apoc to accomplish this bulk relationship creation?

Thanks in advance.

Hi,

I've recently had some success merging large batches of nodes and relationships using this batch method very well summarized by @michael.hunger .

https://medium.com/neo4j/5-tips-tricks-for-fast-batched-updates-of-graph-structures-with-neo4j-and-cypher-73c7f693c8cc

Basically, you can parse both matching criteria and new nodes/relationships with their properties into a JSON-style large string and send it as a parameter of a single cypher statement. I use the process in combination of Python for automation and parallelization, which works really nicely. Let me know if you need more help on this.

1 Like

I still don't get it.
Do you mean that I should apply apoc.map() to my dictionary and then use apoc.iterate()?