Skip to content
Cypher Query Language
step 1/5

Reading — step 1 of 5

Read

~1 min readQuery Languages

Cypher Query Language

Cypher (Neo4j) — the dominant graph query language:

MATCH (alice:Person {name: 'Alice'})-[:KNOWS]->(friend)
RETURN friend.name

Patterns describe shapes:

  • (n): a node, bound to variable n.
  • (n:Person): with label.
  • (n {age: 30}): with property.
  • [r:KNOWS]: a relationship of type KNOWS.
  • -->: directed edge (right).
  • <--: directed edge (left).
  • --: any direction.

Multi-hop:

MATCH (a)-[:KNOWS*1..3]->(b)
WHERE a.name = 'Alice'
RETURN DISTINCT b.name

1-3 hops via KNOWS.

Aggregations:

MATCH (p:Person)
RETURN avg(p.age), count(p)

Mutation:

CREATE (n:Person {name: 'Eve'})
MATCH (a {name: 'Alice'}), (b {name: 'Eve'})
CREATE (a)-[:KNOWS]->(b)
SET a.lastSeen = datetime()
DELETE n
DETACH DELETE n  -- delete node + its relationships

Pattern matching = constraint satisfaction. Optimizer picks join order based on:

  • Statistics (which label has fewer nodes? start there).
  • Index availability (filter via index when possible).
  • Path expansion strategy.

Other languages:

  • Gremlin (TinkerPop): imperative, traversal-style. g.V().has('name', 'Alice').out('KNOWS').
  • GraphQL: declarative, app-friendly; not full graph query language.
  • GSQL (TigerGraph): functional, SQL-like.
  • GQL (ISO standard, 2024): unifies Cypher/Gremlin ideas.

OpenCypher: Cypher's open spec. Implementations: Memgraph, AgensGraph, RedisGraph (deprecated), Apache AGE.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…