Cypher basics: Matching Traversal Patterns with MATCH by Wes Freeman.
From the post:
“Because friends don’t let friends write atrocious recursive joins in SQL.” –Max De Marzi
The
match
clause is one of the first things you learn with Cypher. Once you’ve figured out how to look up your starting bound identifiers withstart
, you usually (but not always) want tomatch
a traversal pattern, which is one of Cypher’s most compelling features.The goal of this post is not to go over the syntax for all of the different cases in
match
–for that the docs do a good job: Cypher MATCH docs. Rather, I hoped to explain more the how of howmatch
works.First, you need to understand the difference between bound and unbound identifiers (sometimes we call them variables, too, in case I slip up and forget to be consistent). Bound identifiers are the ones that you know the value(s) of–usually you set these in the
start
clause, but sometimes they’re passed through withwith
. Unbound identifiers are the ones you don’t know the values of: the part of the pattern you’re matching. If you don’t specify an identifier, and instead just doa-->()
, or something of that sort, an implicit unbound identifier is created for you behind the scenes, so Cypher can keep track of the values it’s found. The goal of thematch
clause is to find real nodes and relationships that match the pattern specified (find the unbound identifiers), based on the bound identifiers you have from thestart
.
Wes is creating enough of these mini-tutorials that you will find his Cypher page, a welcome collection point.