Node and relationship patterns
Node patterns
A node pattern is a pattern that matches a single node.
It can be used on its own in a clause such as MATCH or EXIST, or form part of a path pattern.
See also node pattern concepts.
Syntax
nodePattern ::= "(" [ nodeVariable ] [ labelExpression ]
[ propertyKeyValueExpression ] [ elementPatternWhereClause] ")"
elementPatternWhereClause ::= "WHERE" booleanExpression
For rules on valid node variable names, see the Cypher® naming rules.
Rules
Predicates
Three types of predicate can be specified inside a node pattern:
The boolean expression of the WHERE clause can reference any variables within scope of the node pattern.
A node variable needs to be declared in the node pattern in order to reference it in the boolean expression.
If no predicates are specified, then the node pattern matches any node.
Variable binding
If a variable has not been declared elsewhere in the query, it will become bound to nodes when the matching of its containing path pattern is executed. If it has been bound in a previous clause, then no new nodes will be bound to the variable; any previously bound nodes that do not match in the current path pattern will lead to the match being eliminated from the results. See the section on clause composition for more details on the passing of results between clauses.
Examples
Matches all nodes with the label A and binds them to the variable n:
(n:A)
Matches all nodes with the label B and a property departs with the time value 11:11:
(:B { departs: time('11:11') })
Matches all nodes with the property departs with a value equal to the current time plus 30 minutes:
(n WHERE n.departs > time() + duration('PT30M'))
Relationship patterns
A relationship pattern is a pattern that matches a single relationship. It can only be used with node patterns on either side of it.
A relationship pattern followed immediately by a quantifier is an abbreviated quantified path pattern called a quantified relationship.
See also relationship pattern concepts.
Syntax
relationshipPattern ::= fullPattern | abbreviatedRelationship
fullPattern ::=
"<-[" patternFiller "]-"
| "-[" patternFiller "]->"
| "-[" patternFiller "]-"
abbreviatedRelationship ::= "<--" | "--" | "-->"
patternFiller ::= [ relationshipVariable ] [ typeExpression ]
[ propertyKeyValueExpression ] [ elementPatternWhereClause ]
elementPatternWhereClause ::= "WHERE" booleanExpression
Note that the syntax for type expressions in relationship patterns is the same as for label expressions in node patterns (although unlike node labels, relationships must have exactly one type).
For rules on valid relationship variable names, see the Cypher naming rules.
Rules
Predicates
The following three types of predicate can be specified in the pattern filler of a full relationship pattern (i.e. a pattern with the square brackets):
A fourth type of predicate specifies the directionality of the relationship with respect to the overall path pattern, using the less-than or greater-than symbols to form arrows (< and >).
If a relationship pattern has no arrows, it will match relationships of any direction.
The boolean expression of the WHERE clause can reference any variables within scope of the relationship pattern.
A relationship variable needs to be declared in the pattern in order to reference it in the boolean expression.
If no predicates are specified then the pattern matches all relationships.
Variable binding
If the variable has not been declared elsewhere in the query, it will become bound to relationships when the matching of its containing path pattern is executed. If it has been bound in a previous clause, then no new relationships will be bound to the variable; if any previously bound relationships do not match in the current path pattern, then those matches will be eliminated from the results.
See the chapter on clause composition for more details on the passing of results between clauses.
Examples
Matches all relationships with the type R and binds them to the variable r:
()-[r:R]->()
Matches all relationships with type R and property distance equal to 100:
()-[:R {distance: 100}]->()
Matches all relationships where property distance is between 10 and 100:
()-[r WHERE 10 < r.distance < 100]->()
Matches all relationships that connect nodes with label A as their source and nodes with label B as their target:
(:A)-->(:B)
Matches all relationships that connect nodes with label A and nodes with label B, irrespective of their direction:
(:A)--(:B)
Label expressions
The following applies to both the label expressions of node patterns and the type expressions of relationship patterns.
A label expression is a boolean predicate composed from label names and a wildcard symbol using disjunction, conjunction, negation and grouping. A label expression returns true when it matches the set of labels for a node.
The same grammar appears in label expression predicates in expression context: the colon form element:labelExpression, and as of Neo4j 2026.04, element IS [NOT] LABELED labelExpression (see IS [NOT LABELED]).
Although relationships have a type rather than labels, the syntax for expressions matching a relationship type is identical to that of label expressions.
Syntax
labelExpression ::=
":" labelTerm
| "IS" [ "NOT" ] "LABELED" labelTerm
| "IS NOT" labelTerm
labelTerm ::=
labelIdentifier
| labelTerm "&" labelTerm
| labelTerm "|" labelTerm
| "!" labelTerm
| "%"
| "(" labelTerm ")"
For valid label identifiers, see the Cypher naming rules.
Rules
The following table lists the symbols used in label expressions:
| Symbol | Description | Precedence |
|---|---|---|
|
Wildcard.
Evaluates to |
|
|
Contained expression is evaluated before evaluating the outer expression the group is contained in. |
1 (highest) |
|
Negation |
2 |
|
Conjunction |
3 |
|
Disjunction |
4 (lowest) |
Associativity is left-to-right.
Examples
In the following table, a tick is shown where the label expression matches the node with the labels shown:
Node |
||||||||
Node pattern |
|
|
|
|
|
|
|
|
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
As relationships have exactly one type each, this expression will never match a relationship:
-[:A&B]->
Similarly, the following will always match a relationship:
-[:%]->
The use of negation can make the conjunction useful in relationship patterns.
The following matches relationships that have a type that is neither A nor B:
-[:!A&!B]->
Dynamic label and type expressions
Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables within label expressions.
dynamicLabelExpression ::= ":$(" + valueExpression ")"
The valueExpression must evaluate to a STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL value.
Property key-value expressions
Syntax
propertyKeyValueExpression ::=
"{" propertyKeyValuePairList "}"
propertyKeyValuePairList ::=
propertyKeyValuePair [ "," propertyKeyValuePair ]
propertyKeyValuePair ::= propertyName ":" valueExpression
Rules
The property key-value expression is treated as a conjunction of equalities on the properties of the element that the containing pattern matches.
For example, the following node pattern:
({ p: valueExp1, q: valueExp2 })
is equivalent to the following node pattern with a WHERE clause:
(n WHERE n.p = valueExp1 AND n.q = valueExp2)
The value expression can be any expression as listed in the section on expressions, except for path patterns (which will throw a syntax error) and regular expressions (which will be treated as string literals).
An empty property key-value expression matches all elements.
Property key-value expressions can be combined with a WHERE clause.
Examples
Matches all nodes with property p = 10:
({ p: 10 })
Matches all relationships with property p = 10 and q equal to date 2023-02-10:
()-[{ p: 10, q: date('2023-02-10') }]-()
Matches all relationships with its property p equal to the property p of its source node:
(s)-[{ p: s.p }]-()
Matches all nodes with property p = 10 and property q greater than 100:
(n { p: 10 } WHERE n.q > 100)