Cypher Query in not traversing backwards

I am writing one cypher query like below but not getting the results. I want to find the last node in the path and also need one node before that final node.

MATCH (startNode) - [: FOLLOW | REVIEW | RECOMMENDED*] 
- (lastNode) <- [:RECOMMENDED] - (RecNode)  
WHERE ID(startNode) = 12345   RETURN startNode, lastNode, RecNode

Above query not producing any output. If i split the query into two MATCH statements then I am getting the results

MATCH (startNode) - [: FOLLOW | REVIEW | RECOMMENDED*] 
- (lastNode) WHERE ID(startNode) = 12345   
MATCH (lastNode)  <- [:RECOMMENDED] - (RecNode)  
RETURN startNode, lastNode, RecNode

Can any one please explain why my first query is not working ?
This is working fine in gremlin.

You would get results from the second cypher only (and not from the first cypher) if there is only one relationship of type RECOMMENDED to lastNode. But if it works with gremlin, then it should be another explanation.

1 Like

Thanks @martin3 for your response.
Is it the behavior of cypher which makes first query to fail ?
My gremlin query is like below. This is working fine.

g.V().hasLabel('StartNode').
.repeat(both('FOLLOW','REVIEW','RECOMMENDED')
.simplePath()).until(hasLabel('LastNode')).in('RECOMMENDED')

I think that in the first example there has to be two relationships to lastNode, becuase the same path is not traversed twice. But this does not have to be the case in the second example where the same path could be traversed two times, and I also do not think that this has to be the case for the gremlin example (even though I do not speak any gremlin). This is one thing that could make the first example different from the other two examples, and that COULD potentially be the explanation, but not necessary so and not possible the right explanation, becuase that depends on your data.

So this is just speculations from my side. Maybe someone else have an idea?

1 Like