Search code examples
graphneo4jtreecypherpy2neo

Finding the full network connected with a node in neo4j


Suppose I have a neo4j graph with 3 different kind of nodes (say type A, type B, type C).

There are :

  • 5 nodes of type A
  • 40 nodes of type B
  • 200 nodes of type C

Each node of type A are connecting to one or more of type B ((A -> B)) and each node of type B are connecting to one or more of type C ((B -> C)).

One node of type B can be shared by more than one type A nodes (A1 -> B1, A2 -> B1) and one node of type C can be shared by more than one type B nodes (B1 -> C1, B2 -> C1).

No node of type A connects with any node of type C. And the relationships are directional as described above.

For a given node of type A, can I find out all the nodes in the connected network, i.e., the entire tree emerging from that node, and not just the immediately connected nodes?

So basically I am looking for a py2neo function or cypher query that can give me a full tree or full network emerging from a given node.


Solution

  • Is this query respond to your needs ?

    MATCH p=(a:A)-->(b:B)-->(c:C)
    WHERE a.id = 'your id' // your condition to find your specific A node
    RETURN p