Extrapolate relations between two nodes based on mediated connection

Hello,
i'm in a situation where i have graph of 300 000 nodes where such pattern occurs:

(A:Human)-[R:Has]-(B:Car)-[P:Stolen]-(C:Human)

i would like to create a new "extrapolated" edge:
(A)-[X:ExtrapolatedConnection]-(C)

(in order to be able to find all shortest paths between humans while understanding and assuming the above connection as direct),

however, when i try simply:

MATCH (A:Human)-[R:Has]-(B:Car)-[P:Stolen]-(C:Human)
MERGE (A)-[X:ExtrapolatedConnection]-(C)

the Execution failed and Java heap space error is returned after a while. I guess it's all wrong?
thank you

Hello @ldpubsec and welcome to the Neo4j community :slight_smile:

The dirty solution is to directly increase the heap size of your database in the neo4j.conf file.

The second option is to modify a bit your query like this (it requires APOC plugin):

CALL apoc.periodic.iterate('MATCH (A:Human)-[:Has]-(:Car)-[:Stolen]-(C:Human) RETURN A, C', 'MERGE (A)-[X:ExtrapolatedConnection]-(C)', {batchSize:1000})

Or you can do both :slight_smile:

Regards,
Cobra