Our Path Query:
UNWIND $start_node_hashes AS entityHash
-
MATCH (startNode:Node {id:idValue})*
-
CALL apoc.path.expand(startNode, "", "", 1, 1) YIELD path*
-
WITH startNode, path, relationships(path) AS rels, nodes(path) AS nodes*
-
RETURN startNode, path, rels, nodes*
Next,
We process the result records by reconstructing a graph manually in memory, record/path by path, and that consumes a lot of time. Basically, we do a merge for each node in the path and then bind them together. Thus, nodes and relationships are shared/reused.
Problem:
The underlying graph is very large, and this approach consumes a lot of time.
Question 1:
Is there a way to generate these subgraphs (the recombined entities) in a single step. Basically, extract the subgraph instead of nodes, paths, and relationships that then need to undergo the costly reconstruction effort? If possible, maybe for speed of analytics we project these into an in-memory graph.
Question 2:
Perhaps doing all this in a Neo4j Plugin? This would avoid the repetitive execution of merge commands to create the new subgraph.