Raanan Raz
Raanan Raz

Reputation: 63

Neo4j Cypher: Match Stop At First Match

I have the following paths

1->4
1->2->3->4
1->2->3->4->4

i want to get what are the best paths for 1->4

the expected result is

1->4 
1->2->3->4
without the 1->2->3->4->4)

query example:

match path =  ((p0 { PositionId : 1})-[r*]->( next {PositionId : 4}))
return extract(z IN nodes(path) | z.PositionId),count(*)

Upvotes: 0

Views: 744

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

match path =  (p0 { PositionId : 1})-[r*]->( next {PositionId : 4})
WHERE NOT next in nodes(path)[1..-1]
return extract(z IN nodes(path) | z.PositionId),count(*)

Upvotes: 2

Related Questions