Learn Cypher - 10 Code Examples & CST Typing Practice Test
Cypher is Neo4j’s declarative graph query language designed for creating, querying, and manipulating graph data structures. It uses ASCII-art-like pattern matching to express complex graph relationships intuitively.
Learn CYPHER with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
Basic Cypher Queries
CREATE (a:Person {name: "Alice"})
CREATE (b:Person {name: "Bob"})
CREATE (a)-[:FRIEND]->(b);
MATCH (p:Person)-[:FRIEND]->(f)
RETURN p.name, f.name;
Creating nodes and relationships, then querying them in Neo4j using Cypher.
Advanced Cypher Filtering
MATCH (p:Person)-[:FRIEND*1..2]->(f)
WHERE p.name = "Alice"
RETURN f.name;
Using WHERE clauses and relationship depth in Neo4j queries.
Neo4j Aggregation
MATCH (p:Person)-[:FRIEND]->(f)
RETURN p.name, COUNT(f) AS friend_count
ORDER BY friend_count DESC;
Counting friends per user with Cypher aggregation.
Neo4j Path Matching
MATCH p = (a:Person {name:"Alice"})-[:FRIEND*2]->(b:Person)
RETURN p;
Querying all paths of a certain length between nodes.
Neo4j Create With Properties
CREATE (c:Company {
name: "TechCorp",
founded: 2020,
location: "NYC"
});
Creating a node with multiple properties in Cypher.
Neo4j Relationship Properties
MATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})
CREATE (a)-[:WORKED_WITH {since: 2021}]->(b);
Adding properties to relationships in Neo4j.
Neo4j Delete Nodes
MATCH (p:Person {name: "Alice"})
DETACH DELETE p;
Deleting nodes and relationships in Neo4j.
Neo4j Indexes
CREATE INDEX person_name_index FOR (p:Person) ON (p.name);
Creating an index on node properties in Neo4j.
Neo4j Constraints
CREATE CONSTRAINT unique_email IF NOT EXISTS
FOR (p:Person)
REQUIRE p.email IS UNIQUE;
Adding uniqueness constraint to ensure unique property values.
Neo4j Full-Text Search
CALL db.index.fulltext.createNodeIndex("personIndex", ["Person"], ["name","email"]);
CALL db.index.fulltext.queryNodes("personIndex", "Alice")
YIELD node, score
RETURN node.name, score;
Using full-text indexes to search across multiple properties.
Frequently Asked Questions about Cypher
What is Cypher?
Cypher is Neo4j’s declarative graph query language designed for creating, querying, and manipulating graph data structures. It uses ASCII-art-like pattern matching to express complex graph relationships intuitively.
What are the primary use cases for Cypher?
Graph traversal and pathfinding. Recommendation systems. Social network analysis. Fraud detection and link analysis. Knowledge graphs and semantic search. Network and IT infrastructure mapping
What are the strengths of Cypher?
Intuitive pattern-based syntax. High performance for relationship-heavy queries. Strong ecosystem (APOC, GDS library). Excellent visualization in Neo4j Browser. Supports complex graph analytics
What are the limitations of Cypher?
Not ideal for massive tabular datasets. Requires graph modeling expertise. Performance depends on proper indexing. Limited JOIN-like operations outside graph context
How can I practice Cypher typing speed?
CodeSpeedTest offers 10+ real Cypher code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.