Find the shortest path between 2 nodes with RedisGraph

1k views Asked by At

I have simple nodes with integer ids. I just want to find the shortest path between to nodes given their id. I tried :

GRAPH.QUERY mygraph "MATCH p=(startnode)-[*]-(endnode) WHERE ID(startnode)=2 AND ID(endnode)=1 RETURN p"

or something with algo.BFS but no example is given

GRAPH.QUERY mygraph "CALL algo.BFS source-node YIELD redisnodes,redisedges"

But I didn't succeed. Is this feature available ?

1

There are 1 answers

2
SWilly22 On

This is one option (a bit expensive)

MATCH p = (a{v:1})-[*]-(c {v:2}) WITH collect(p) AS paths, min(length(p)) AS min_len RETURN [p in paths WHERE length(p) = min_len | p][0]

Another option would have to be algo.BFS but it will require additional client side processing.