liveBook · Manning

Match clause

As explained in Graph Algorithms for Data Science

A MATCH clause is a Cypher query clause that finds stored graph patterns and binds their elements to query variables.

MATCH is the Cypher clause for finding graph patterns already stored in a database. Write the node and relationship pattern you want; Cypher’s declarative query engine determines how to retrieve matching data and binds the matched elements to variables for later clauses. section 3.1.2 section 3.4

Find a person by label and property

Match a labeled node inline, then return its bound variable. Inline properties make a compact pattern description; a WHERE clause can express the same label and property conditions. Combining an inline label with WHERE filters is a readable way to add conditions and alias output columns. section 3.1.2

Listing 3.6 Cypher statement that searches and retrieves any nodes with a label Person and a name property with a value of Satish
MATCH (p:Person {name:'Satish'})
RETURN p

This minimal query matches the Person node whose name is Satish and returns the variable p. section 3.1.2

Use MATCH as the selection step before other work:

  • Chain MATCH clauses to find separate patterns. Each WHERE applies only to the MATCH immediately before it. section 3.1.2
  • Use MATCH before DELETE to select the relationship or node that should be removed. Omitting a relationship type matches relationships of any type between the described nodes. section 3.1.6
  • Match existing CSV-identified nodes before MERGE creates imported relationships. If a required pattern is absent, processing for that row does not continue. section 3.2.5
  • Use OPTIONAL MATCH when a missing pattern should not discard other variables and rows from the result. section 3.1.2 section 3.4
  • Match a two-hashtag pattern in a tweet, then count and rank the pairs to examine co-occurrence; constrain node IDs to remove mirrored duplicates. section 7.2

A regular MATCH is required: if it finds no specified pattern, the statement returns no results. This matters when matching several patterns, because one missing required match prevents a combined result. OPTIONAL MATCH preserves the available part of a query instead. section 3.1.2 section 3.4

How Graph Algorithms for Data Science covers it

How deep it goes
Explains inline and WHERE-based matching, clause scope, absent-match behavior, and practical uses without query-engine internals.
Examples
Demonstrates Person lookups, relationship deletion, Twitter CSV imports, and counting co-occurring hashtag pairs.
What it assumes
Assumes familiarity with Cypher node and relationship pattern syntax before using MATCH to retrieve those patterns.
What you can do after
Apply it via Cypher to retrieve patterns, filter matches, safely retain optional data, and select graph elements for later clauses.
How it connects
Connects MATCH with WHERE, OPTIONAL MATCH, RETURN, DELETE, MERGE, WITH, count(), and Cypher projection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.