I am trying to get the neighbors of a given root node at the n
hop distance.
I can use the following query on a small graph, or when the root node has few neighbors.
MATCH (root: Person { Name: "somename" })
CALL apoc.path.spanningTree(root, {
maxLevel: 3,
bfs: true,
labelFilter: 'Person'
}
YIELD path
WITH
root,
nodes(path) AS pathNodes,
relationships(path) AS pathRels
RETURN
[root] AS root,
[n IN pathNodes WHERE n <> root] AS nodes,
pathRels AS relationships
However, when the root node has many neighbors at n
hop distance (hundreds of millions), I run into out-of-memory related issues.
I need all the neighbors, hence, I do not limit the output size.
I was wondering if there is any way of streaming the neighbors of a given root node at n
hop distance to an output file, such that they are serialized to a file as they are found instead of being collected in the memory.