apoc.algo.allSimplePaths

Procedure APOC Core

apoc.algo.allSimplePaths(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 5) YIELD path, weight - run allSimplePaths with relationships given and maxNodes

Signature

apoc.algo.allSimplePaths(startNode :: NODE?, endNode :: NODE?, relationshipTypesAndDirections :: STRING?, maxNodes :: INTEGER?) :: (path :: PATH?)

Input parameters

Name Type Default

startNode

NODE?

null

endNode

NODE?

null

relationshipTypesAndDirections

STRING?

null

maxNodes

INTEGER?

null

Output parameters

Name Type

path

PATH?

Usage Examples

The examples in this section are based on the following sample graph:

CREATE
  (a:Loc{name:'A'}),
  (b:Loc{name:'B'}),
  (c:Loc{name:'C'}),
  (d:Loc{name:'D'}),
  (a)-[:ROAD {d:100}]->(d),
  (a)-[:RAIL {d:5}]->(d),
  (a)-[:ROAD {d:'10'}]->(b),
  (b)-[:ROAD {d:20}]->(c),
  (c)-[:ROAD]->(d),
  (a)-[:ROAD {d:20}]->(c);

We can return all the paths between A and D, by running the following query:

MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'})
CALL apoc.algo.allSimplePaths(from, to, 'ROAD>', 3)
YIELD path
RETURN path ORDER BY length(path);
Table 1. Results
path (:Loc {name: "A"})-[:ROAD {d: 100}]→(:Loc {name: "D"})

(:Loc {name: "A"})-[:ROAD {d: 20}]→(:Loc {name: "C"})-[:ROAD]→(:Loc {name: "D"})

(:Loc {name: "A"})-[:ROAD {d: "10"}]→(:Loc {name: "B"})-[:ROAD {d: 20}]→(:Loc {name: "C"})-[:ROAD]→(:Loc {name: "D"})