Learn CYPHER with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
1
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.
2
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.
3
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.
4
Neo4j Path Matching
MATCH p = (a:Person {name:"Alice"})-[:FRIEND*2]->(b:Person)
RETURN p;
Querying all paths of a certain length between nodes.
5
Neo4j Create With Properties
CREATE (c:Company {
name: "TechCorp",
founded: 2020,
location: "NYC"
});
Creating a node with multiple properties in Cypher.
6
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.
7
Neo4j Delete Nodes
MATCH (p:Person {name: "Alice"})
DETACH DELETE p;
Deleting nodes and relationships in Neo4j.
8
Neo4j Indexes
CREATE INDEX person_name_index FOR (p:Person) ON (p.name);
Creating an index on node properties in Neo4j.
9
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.
10
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.