2
votes

I would like to input two specific nodes and return the quantity of relationships that are along the path that connect the specific nodes. (There is only 1 path possible in every case)

In some cases, two specific nodes are related through two relationships like this:

(Tim)-[]-()-[]-(Bill)

Should return 2 (relationships).

In other cases there are more nodes between my specific start and end nodes. Like this:

(Tim)-[]-()-[]-()-[]-()-[]-(Bill)

Should return 4 (relationships).

I have two types of relationships that could exist between nodes, so I need to avoid being specific about the type of relationship if possible.

New to this and performed an extensive search before asking this question as no one seemed to discuss relationships between specific nodes...

Many thanks for your help!

1

1 Answers

3
votes

This query should work:

match p = (:Person {name:'Tim'})-[*]->(:Person {name:'Bill'})
RETURN length(p)

That is: return the length() of path p.