Skip to main content

🔍 MATCH: Pattern Matching

MATCH (n) RETURN n
MATCH (n:Person{name="Alice"}) RETURN n.age
MATCH (a)-[e]-(b) RETURN *
MATCH (a:Person)--(b:Company) RETURN a.name, b.name
  • () → Node
  • [] → Edge
  • - → Undirected edge
  • Labels: :Label
  • Properties: {key="value", age=30}

🛠 CREATE: Add Nodes & Edges

CREATE (n:Person{name="Alice", age=30})
CREATE (:Person)-[:FRIEND_OF]-(:Person)
CREATE (a:Corner)-[:Edge]-(b), (b)-[:Edge]-(c), (c)-[:Edge]-(a)
  • Labels required
  • No RETURN clause
  • Use commas to create multiple items at once

🎯 Property Match Operators

MATCH (n{name="Alice"}) RETURN n
MATCH (n{name~="apoe"}) RETURN n        -- Approximate match
MATCH (n{age=42u}) RETURN n             -- Unsigned int
  • = or : → exact match
  • ~= → string approximation (prefix-based, case-insensitive)

📦 Data Types

TypeExample
String"hello" or 'hello'
Integerage=30
Unsignedage=30u
Booleanflag=true
Doublescore=3.14

✨ RETURN Clause

MATCH (n)--(m) RETURN n.name, m.age
MATCH (n)--(m) RETURN *
  • RETURN * → expands to all variables
  • Select fields with RETURN n.prop, m.prop

📌 Node ID Injection

MATCH (n @ 1) RETURN n
MATCH (n:Person @ 1, 2, 3) RETURN n.name
  • Use @ or AT to reference internal IDs

🔬 Metaqueries (CALL)

QueryDescription
CALL PROPERTIES()All node/edge property keys & types
CALL LABELS()All node labels
CALL EDGETYPES()All edge types
CALL LABELSETS()Combinations of labels

🔧 Engine Commands

CommandDescription
CREATE GRAPH <name>Create a new named graph
LOAD GRAPH <name>Load an existing graph
LIST GRAPHList all available graphs
HISTORYShow commit history (versioning)
CHANGE NEWCreate a new isolated change
CHANGE SUBMITMerge current change into main
CHANGE DELETEDelete current change
CHANGE LISTList active uncommitted changes

🧠 Useful Patterns

-- Two-hop connection
MATCH (a)-[r1]-(b)-[r2]-(c) RETURN c

-- All people named John
MATCH (n:Person{name="John"}) RETURN n

-- All nodes with approx match
MATCH (n{name~="kinase"}) RETURN n

📘 Best Practices

  • Use CALL PROPERTIES() to discover property keys
  • Use RETURN * while prototyping
  • Use @ for precise node editing or merging
  • Avoid regex — use ~= for faster fuzzy search
  • All edges are currently undirected
I