K-Hop template khop().<path_template>
takes the path template as parameters of K-hop command when finding k-hop neighbors. Upon achieving the same query function, K-Hop template yields better performance than path template.
Syntax:
- Statement alias supported (NODE type)
- The template
n()
for initial-node must have filtering rules [<steps>]
in multiple edges template must be a definite value, namely[N]
- Inter-step filtering of any type is illegal, no matter using
prev_n
,prev_e
or preceding custom alias defined in the current path template
Common Usage
Example: Find the cards that Customer CU001's card reaches in 2-step shortest transaction paths, return the count of card's owners with all properties
khop()
.n({_id == "CU001"}).re().n({@card})
.le({@transfer})[2].n({@card})
.le().n({@customer}) as n
return n{*}
Analysis: This example can be regarded as a K-Hop query as it queries the dest of the shortest path. For khop()
command itself cannot set different rules to filter the directions and properties for the edges that appear sequentially in the path, it's necessary to use template to implement the entire UQL statement.
Example: as the path structure shown in the graph below, find the cards using the same phone numbers used by Customer CU013 and CU020's cards, count the number of these cards

khop()
.n({_id in ["CU013","CU020"]}).re().n({@card})
.re().n({@phone})
.le().n({@card}) as n
return count(n)