shortestPath processor runs a Dijkstra search from a source set of nodes to a target set of nodes, returning the shortest distance and the path taken based on a numeric edge weight property.
Sample dataset
The examples on this page use a small railway network. Run the following query to create it:Syntax
| Parameter | Description |
|---|---|
sourceSet | Variable bound to the source node(s) via a preceding MATCH clause |
targetSet | Variable bound to the target node(s) via a preceding MATCH clause |
edgePropName | Name of the numeric edge property to use as weight |
distanceReturnVar | Output variable name for the total shortest distance |
pathReturnVar | Output variable name for the path string |
Basic usage
- Cypher
- Python SDK
Returning only the distance or only the path
Both output variables are always computed — you can choose to return one or both:- Cypher
- Python SDK
Multiple sources or targets
You can pass multiple nodes to the source or target set —shortestPath will find the shortest distance across all combinations and return the best one:
- Cypher
- Python SDK

