How to search for multiple variable length path relationships?

Please format code + Cypher statements with the code </> icon, it's much easier to read.

I am trying to see how to run a MATCH query where I can see all paths from a certain Node with a specific property key to all Nodes with another specific property type but with out going past the first instance of the second node.


MATCH p=(c:Customer)-[*..5]-(e:Equip)

I want to do this search for the CID property of the Customer nodes and get the 2 paths to the first Equip node down each path that has the property Router. This path could be 2 relationships away or it could be 8. But, if both paths are only 2 away then [*..8] will go past the first Equip:Router node and find many others.. is there a relationship rule or some other method I can use to make sure I ONLY get to each of the FIRST Nodes with the property Router?

Do you mean "the label Router"?

If so, the apoc subgraph functions can probably help you out (especially by using a terminatorNode label)

That's not a bad idea. I have now spent the past few hours trying to figure out how to properly format that code. I have set all Equip nodes with a property key of ROUTER to also have a label of ROUTER as well... how would I format the call?


Were you able to get this working for you?

If not, an example that may work for you may look something like this:

MATCH (c:Customer)
CALL apoc.path.spanningTree(c, {labelFilter:'/ROUTER', maxLevel:5}) YIELD path

(it's called "spanningTree" because the set of all paths from it collectively form one...but basically it does the same thing that subgraphNodes() does, but returns paths instead of just the nodes at the end of each path)

This sort of works as do the previous responses others provided me, though I add '-Customer' to prevent it from flowing through another customer to find the routers. The other issue I am coming across though is when one of the pieces of equipment along the path is connected to more than one Router nodes via handoff nodes, then the results of the call may send me to one of those Routers instead of the Router that is actually in the path for the Customers service path. I have not been able to find a way to make sure that the path for that specific CID/Customer is always guaranteed via the call.