Live graph algorithms
Graph algorithms
These run directly on the live graph (no named projections). The illustrative
IDs below must be replaced with existing IDs from your database. Use
application keys to find nodes first. The
direction argument accepts 'OUT'/'OUTGOING', 'IN'/'INCOMING', or
anything else for both directions.
| Procedure | YIELD | Args |
|---|---|---|
gdb.dijkstra(sourceId, targetId, relType, weightProp, direction) | nodeIds, totalCost, path | node ids (int), relationship type (string), weight property name (string; omit/empty → each hop costs 1), direction |
gdb.astar(sourceId, targetId, relType, weightProp, pointProp, direction) | nodeIds, totalCost, path | as Dijkstra, plus pointProp — a Point property used for the straight-line heuristic |
gdb.pageRank(relType, iterations, dampingFactor) | nodeId, score | type (string), iterations (int, default 20), damping (float, default 0.85) |
gdb.degree(nodeId, direction) | degree | node id (int), direction |
// shortest weighted path from node 0 to node 42 over :ROAD by 'km':
CALL gdb.dijkstra(0, 42, 'ROAD', 'km', 'OUT')
YIELD nodeIds, totalCost, path
RETURN nodeIds, totalCost;
// A* using a 'loc' point property as the heuristic:
CALL gdb.astar(0, 42, 'ROAD', 'km', 'loc', 'OUT') YIELD totalCost RETURN totalCost;
// PageRank over :LINKS, 30 iterations:
CALL gdb.pageRank('LINKS', 30, 0.85) YIELD nodeId, score
RETURN nodeId, score ORDER BY score DESC LIMIT 10;
CALL gdb.degree(0, 'OUT') YIELD degree RETURN degree;
Cypher also offers
shortestPath/allShortestPathsfor unweighted shortest paths inside aMATCH— see Paths and shortest-path queries.
Related articles
Graph projections and catalogue · GDS algorithms and execution modes · GDS resources and cancellation · Graph data science