One-to-Many Shortest Path query support in Neo4j

2019-07-09 20:45发布

问题:

Does neo4j have support for one-to-many shortest path queries? An example of such query would be: Given a node i, and a list of several other nodes N, compute the shortest paths from i to all the nodes that belong to N.

I am aware of this thread: Neo4j shortest path (BFS) distances query variants, but it is specifically for one-to-all queries. My question is for one-to-many queries.

Thank you.

回答1:

To get All paths from one node to multiple nodes

MATCH p = shortestPath((s:skill)-[r]->(s1:skill))
WHERE id(s) = 123
AND id(s1) IN [1,2,3]

RETURN p

This is the one way to get paths between one-to-many. I hope this is what you need.