When the relationship is of the same type, as in our example, or, if we do not care about the relationship type, we can use the following shortcut:
MATCH (:State {code: "FL"})-[:SHARE_BORDER_WITH*2]-(neighbor_of_neighbor)
RETURN neighbor_of_neighbor
This will return the same six results that we have already seen in the previous section with this query:
(FL:State {code: "FL"})-[:SHARE_BORDER_WITH]-(neighbor)-[:SHARE_BORDER_WITH]-(neighbor_of_neighbor)
You can give lower and upper values for the number of hops with this syntax:
[:SHARE_BORDER_WITH*<lower_value>..<upper_value>]
For instance, [:SHARE_BORDER_WITH*2..3] will return the neighbors with two or three degrees of separation.
It is even possible to use whatever path length using the * notation, like so:
[:SHARE_BORDER_WITH*]
This will match paths regardless of the number of relationships. However, this syntax is not recommended since it can create a huge performance decrease...