Article DetailsDetailsHelp Details Consider a number of arbitrary nodes, A,B,C,D,E,F,….. I wish to return all of the shortest paths between these nodes. The nodes may have many edges between them, but anticipate a maximum of 4. The graph is complex and non hierarchical (if this makes sense - any node may point to any other node). A typical node has the form: match (n:Entity { name: 'xyz' }) How would I write the match expression to return the shortest paths between the above nodes, in no specific order? Solution Find the set of nodes using an indexed lookup operationCollect them into a listUnwind the list twice, once for every side of the pathRemove inverse pairs by id comparisonmatch and return the paths MATCH (n:Entity) where n.name IN $names WITH collect(n) as nodes UNWIND nodes as n UNWIND nodes as m WITH * WHERE id(n) < id(m) MATCH path = allShortestPaths( (n)-[*..4]-(m) ) RETURN path InformationTitleAll shortest paths between a set of nodesArticle Created Date3/15/2024, 10:56 PMURL Name115009519288-All-shortest-paths-between-a-set-of-nodesLast Modified Date3/18/2024, 10:47 AM