Skip to content

FIND PATH

The FIND PATH statement finds the paths between the selected source vertices and destination vertices.

Syntax

FIND { SHORTEST | ALL | NOLOOP } PATH [WITH PROP] FROM <vertex_id_list> TO <vertex_id_list>
OVER <edge_type_list> [REVERSELY | BIDIRECT] 
[<WHERE clause>] [UPTO <N> STEPS] 
YIELD path as <alias>
[| ORDER BY $-.path] [| LIMIT <M>];

<vertex_id_list> ::=
    [vertex_id [, vertex_id] ...]
  • SHORTEST finds the shortest path.
  • ALL finds all the paths.
  • NOLOOP finds the paths without circles.
  • WITH PROP shows properties of vertices and edges. If not specified, properties will be hidden.
  • <vertex_id_list> is a list of vertex IDs separated with commas (,). It supports $- and $var.
  • <edge_type_list> is a list of edge types separated with commas (,). * is all edge types.
  • REVERSELY | BIDIRECT specifies the direction. REVERSELY is reverse graph traversal while BIDIRECT is bidirectional graph traversal.
  • <WHERE clause> filters properties of edges.
  • <N> is the maximum hop number of the path. The default value is 5.
  • <M> specifies the maximum number of rows to return.

Note

The path type of FIND PATH is trail. Only vertices can be repeatedly visited in graph traversal. For more information, see Path.

Limitations

  • When a list of source and/or destination vertex IDs are specified, the paths between any source vertices and the destination vertices will be returned.
  • There can be cycles when searching all paths.
  • FIND PATH only supports filtering properties of edges with WHERE clauses. Filtering properties of vertices and functions are not supported for now.
  • FIND PATH is a single-thread procedure, so it uses much memory.

Examples

A returned path is like (<vertex_id>)-[:<edge_type_name>@<rank>]->(<vertex_id).

nebula> FIND SHORTEST PATH FROM "player102" TO "team204" OVER * YIELD path AS p;
+--------------------------------------------+
| p                                          |
+--------------------------------------------+
| <("player102")-[:serve@0 {}]->("team204")> |
+--------------------------------------------+
nebula> FIND SHORTEST PATH WITH PROP FROM "team204" TO "player100" OVER * REVERSELY YIELD path AS p;
+--------------------------------------------------------------------------------------------------------------------------------------+
| p                                                                                                                                    |
+--------------------------------------------------------------------------------------------------------------------------------------+
| <("team204" :team{name: "Spurs"})<-[:serve@0 {end_year: 2016, start_year: 1997}]-("player100" :player{age: 42, name: "Tim Duncan"})> |
+--------------------------------------------------------------------------------------------------------------------------------------+
nebula> FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0 YIELD path AS p;
+------------------------------------------------------------------------------+
| p                                                                            |
+------------------------------------------------------------------------------+
| <("player100")-[:serve@0 {}]->("team204")>                                   |
| <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")>     |
| <("player100")-[:follow@0 {}]->("player101")-[:serve@0 {}]->("team204")>     |
|...                                                                           |
+------------------------------------------------------------------------------+
nebula> FIND NOLOOP PATH FROM "player100" TO "team204" OVER * YIELD path AS p;
+--------------------------------------------------------------------------------------------------------+
| p                                                                                                      |
+--------------------------------------------------------------------------------------------------------+
| <("player100")-[:serve@0 {}]->("team204")>                                                             |
| <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")>                               |
| <("player100")-[:follow@0 {}]->("player101")-[:serve@0 {}]->("team204")>                               |
| <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")> |
| <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player102")-[:serve@0 {}]->("team204")> |
+--------------------------------------------------------------------------------------------------------+

FAQ

Does it support the WHERE clause to achieve conditional filtering during graph traversal?

FIND PATH only supports filtering properties of edges with WHERE clauses, such as WHERE follow.degree is EMPTY or follow.degree >=0.

Filtering properties of vertices is not supported for now.


Last update: February 19, 2024