I'm quite new to Cypher but struggling to find how to do this. I want to generalise the following so that it will match at an arbitrary depth.
MATCH (:start)-[:a]-()-[:b]-(:end) //Depth1
MATCH (:start)-[:a]-()-[:b]-()-[:a]-()-[:b]-(:end) //Depth2
MATCH (:start)-[:a]-()-[:b]-()-[:a]-()-[:b]-()-[:a]-()-[:b]-(:end) //Depth3
MATCH (:start)-[:a]-()-[:b]-()-[:a]-()-[:b]-()-[:a]-()-[:b]-()-[:a]-()-[:b]-(:end) //Depth4
In other words, the path needs to pass through any number of a-node-b in strict alternation; a-node-a etc. will not work. So I can't do this, as per Neo4J: find a sub-graph of arbitrary depth with nodes connected by a given set of relations?
MATCH (:start)-[:a|b*]-(:end)
because that would match things like this:
MATCH (:start)-[:a]-()-[:a]-(:end)
MATCH (:start)-[:b]-()-[:b]-(:end)
Does anyone know how to solve this? I'm using Cypher with Neo4j 2.x if it matters.
Thanks!