Cypher: Find any path between nodes

Viewed 3326

I have a neo4j graph that looks like this:

Graph overview

Nodes:

  1. Blue Nodes: Account
  2. Red Nodes: PhoneNumber
  3. Green Nodes: Email

Graph design:

  • (:PhoneNumber) -[:PART_OF]->(:Account)
  • (:Email) -[:PART_OF]->(:Account)

The problem I am trying to solve is to

Find any path that exists between Account1 and Account2.

This is what I have tried so far with no success:

  1. MATCH p=shortestPath((a1:Account {accId:'1234'})-[]-(a2:Account {accId:'5678'})) RETURN p;
  2. MATCH p=shortestPath((a1:Account {accId:'1234'})-[:PART_OF]-(a2:Account {accId:'5678'})) RETURN p;
  3. MATCH p=shortestPath((a1:Account {accId:'1234'})-[*]-(a2:Account {accId:'5678'})) RETURN p;
  4. MATCH p=(a1:Account {accId:'1234'})<-[:PART_OF*1..100]-(n)-[:PART_OF]->(a2:Account {accId:'5678'}) RETURN p;
  5. Same queries as above without the shortest path function call.

By looking at the graph I can see there is a path between these 2 nodes but none of my queries yield any result. I am sure this is a very simple query but being new to Cypher, I am having a hard time figuring out the right solution. Any help is appreciated.

Thanks.

1 Answers
Related