UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Reserved Words
    • Data Types
    • Alias
    • Operators
    • Expression
    • Filter
    • Prefix
    • Node and Edge Templates
    • Homologous and Heterologous Data
    • Clause Execution Times
    • Graphset
    • Schema
    • Property
    • Insert
    • Overwrite
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • Find Subgraphs
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • BATCH
      • Schema Checker
      • Equal
      • Not Equal
      • Less Than
      • Greater Than
      • Less Than or Equal
      • Greater Than or Equal
      • Between
      • Between or Equal
      • Beong to
      • Not Belong To
      • CONTAINS | String
      • CONTAINS | Full-Text
      • Regular Match
      • IS NULL
      • IS NOT NULL
      • And
      • Or
      • Not
      • Exclusive OR
      • DISTINCT
      • toString()
      • toInteger()
      • toFloat()
      • toDouble()
      • toDecimal()
      • toSet()
      • castToRaw()
      • now()
      • dateAdd()
      • dateDiff()
      • year()
      • month()
      • day()
      • dayOfWeek()
      • dateFormat()
      • point()
      • distance()
      • pointInPolygon()
      • lower()
      • upper()
      • reverse()
      • startsWith()
      • endsWith()
      • JSON_decode()
      • JSON_merge()
      • trim()
      • ltrim()
      • rtrim()
      • left()
      • right()
      • substring()
      • replace()
      • split()
      • intersection()
      • difference()
      • listUnion()
      • size()
      • head()
      • reduce()
      • listContains()
      • append()
      • pi()
      • pow()
      • sqrt()
      • abs()
      • floor()
      • ceil()
      • round()
      • sin()
      • cos()
      • tan()
      • cot()
      • asin()
      • acos()
      • atan()
      • length()
      • pnodes()
      • pedges()
      • count()
      • sum()
      • max()
      • min()
      • avg()
      • stddev()
      • collect()
      • dedup()
      • CASE
      • table()
      • coalesce()
      • ifnull()
    • Acceleration
    • Index
    • Full-text
    • LTE
    • Real-time Process
    • Backend Task
    • Analytics Node
    • Server Statistics
    • Server Backup
    • Privilege
    • Policy
    • User
  • Trigger
  1. Docs
  2. /
  3. UQL
  4. /
  5. Syntax

Node and Edge Templates

Overview

Node and edge templates serve as buliding blocks for constructing paths and subgraphs. By incorporating filters that define the nodes and edges involved, these templates can accurately match patterns across various scenarios.

Templates

There are four basic node and edge templates:

Template
Name
Description
Custom Alias
n()Single node
Supported, type: NODE
e(),
le(),
re()
Single edge

(Direction: ignored, left, right)
Supported, type: EDGE
e()[<steps>],
le()[<steps>],
re()[<steps>]
Multi-edge

(Direction: ignored, left, right)

Formats of [<steps>]: (N≥1)
[N]: N edges
[:N]: 1~N edges
[M:N]: M~N edges[1] (M≥0)
[*:N]: the shortest paths within N edges
Not supported
e().nf()[<steps>],
le().nf()[<steps>],
re().nf()[<steps>]
Multi-edge with intermediate nodes

(Direction: ignored, left, right)

Formats of [<steps>] is same as above
Not supported

[1] When setting [0:N] for a multi-edge template, the step 0 is valid only when the n() before the multi-edge template meets the filtering condition of the n() after the multi-edge template. In this case, this multi-edge template along with the right side n() are considered dismissed.

Path Composition Rules

Rule 1: A path starts and ends with a node, and consists of alternating nodes and edges in between.

Example: The paths below with a length of 3 can be expressed as n().e().n().e().n().e().n(), each individual node and edge template in the path can have its own filter and alias.

UQL
n({@mgr}).re({@manage}).n({@cst} as n1)
  .re({@has}).n({@acct} as n2)
  .re({@buy} as e1).n({@product}) as p
return n1, n2, e1, p

Particularly, it's supported to use n() independently.

Example: Find all @account nodes.

UQL
n({@account} as acc)
return acc

Rule 2: Consecutive edges and nodes with same filtering condition can be merged into a multi-edge template.

Example: The paths below have the same types of edges and nodes from step 2 to step 4. You can use the multi-edge template e().nf()[3] to represent those edges and intermediate nodes. However, custom alias is not applicable in multi-edge template.

UQL
n({@cst}).re({@has}).n({@acct} as n1)
  .re({@transfer}).nf({@acct})[3].n({@acct} as n2)
  .le({@has}).n({@cst}) as p
return n1, n2, p

Rule 3: Set the steps as a range instead of a fixed number when applicable to expand the query scope.

Example: You can use the multi-edge template e().nf()[:3] to limit the number of transactions in paths within 3, as shown below.

UQL
n({@cst} as n1).re({@has}).n({@acct} as c1)
  .re({@transfer})[:3].n({@acct} c1)
  .le({@has}).n({@cst}) as p
return c1, c2, p