I'm developing something for learning graph databases.I'm finding the shortest path that query in the following segment:
start n=node(5),m=node(45) match p=shortestPath(n-[*..1000]->m) return p,length(p)
But I have problem about that.That query will return the shortest path and not considered with ROUTE properties.I mean, I want to get shortest path with a relation, if there is exist same property.
Node A ==> :RELATION(ROUTE_ID=180) ==> Node B ==> :RELATION(ROUTE_ID=180) ==> NODE C ==> :RELATION(ROUTE_ID=197)
When I call the normal shortest path function, it gives me relationships by random properties.I want to focus on properties also.What is the keyword for that? How can I fix that problem or How can I improve that query?
Thanks.
If all relationships with the ROUTE_ID property have a specific relationship type, say 'ROUTE', then you can do this:
START n=node(5), m=node(45)
MATCH p=shortestPath(n-[:ROUTE*..1000]->m)
RETURN p,length(p);
Otherwise, you can do this:
START n=node(5), m=node(45)
MATCH p=shortestPath(n-[r*..1000]->m)
WHERE all(x IN r WHERE has(x.ROUTE_ID))
RETURN p,length(p);
The former approach should be much faster.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.