If I understand you right you're not actually using Neo4j 2.0 :Label
labels on your nodes, but a property called label
on your relationships? If so a general query could be something like
START root=node(0)
MATCH path=root<-[rels:IS_BEFORE*1..100]-leaf
WHERE ALL(rel in rels WHERE rel.label = "branch 1")
RETURN EXTRACT(n in nodes(path) | ID(n)) as nodeIdSequence
This is probably not very efficient since it matches all branches and only limits the result to the relevant branch afterwards. It would be more efficient to identify the branch by relationship type, something like (root)-[:NEXT_ON_BRANCH_1]->(branchNode)
. Alternatively you could do the match in two steps: 1) match the first node on each branch and find the right branch. 2) Now that you know you have the right branch, match the rest of it. You could try something like
START root=node(0)
MATCH root<-[r:IS_BEFORE]-branch
WHERE r.label = "branch 1"
WITH branch
MATCH path=branch<-[:IS_BEFORE*1..100]-leaf
RETURN EXTRACT(n in nodes(path) | ID(n)) as nodeIdSequence
If this is not what your model looks like, please share sample data at http://console.neo4j.org
(Depth limit *1..100
above is arbitrary, set it to whatever you want, but usually setting some limit is a good idea.)