Neo4j explained: model a graph and query relationships with Cypher
Neo4j stores data as nodes, directed relationships between nodes, and properties on either. When an answer depends on following several connections, Cypher’s `MATCH` clause lets you describe a path pattern and retrieve matching data. For writes that may run repeatedly, distinguish `CREATE`, which always adds new data, from `MERGE`, which matches or creates a pattern; use stable identifiers and uniqueness constraints to control duplicates.
Neo4j stores data as nodes, directed relationships between nodes, and properties on either. When an answer depends on following several connections, Cypher’s MATCH clause lets you describe a path pattern and retrieve matching data. For writes that may run repeatedly, distinguish CREATE, which always adds new data, from MERGE, which matches or creates a pattern; use stable identifiers and uniqueness constraints to control duplicates.
Scope: Neo4j’s current official Getting Started and Cypher Manual documentation, checked November 23, 2026. This introduction does not cover deployment-specific setup, pricing, or cluster operations. Examples are illustrative and were not run.
What makes up a Neo4j graph?
A node represents an entity such as a person, product, or account. A label identifies a node’s role, and properties store key-value details such as a name or ID. A relationship connects two nodes and has a start, an end, a direction, and exactly one type. Relationships can also have properties—for example, a purchase date or quantity. (Person)-[:PURCHASED]->(Product) represents a directed purchase link.
Relationships are data elements in the graph rather than connections implied only by foreign-key values. That makes it natural to ask who a person follows or which supplier is connected to a product through several parts. Yet connected data alone does not mean everything belongs in a graph. If most questions are single-record lookups or column aggregations, a table-oriented database may be simpler. Neo4j graph database overview · Cypher core concepts
How does Cypher express a graph query?
Cypher is Neo4j’s declarative query language for finding or creating graph patterns. Parentheses represent nodes, square brackets represent relationships, and arrows show direction. (a:Person)-[:FOLLOWS]->(b:Person) describes a FOLLOWS relationship from one Person node to another. MATCH finds data that fits the pattern; RETURN selects what to show.
MATCH (buyer:Person {id: 'u-17'})-[:PURCHASED]->(item:Product)
RETURN item.name AS product;This illustrative query starts from the person with ID u-17 and follows purchase relationships to product names. It was not executed and makes no performance claim. Narrow patterns with labels, properties, relationship types, and direction so the query does not explore unintended paths. An undirected pattern can match without regard to stored direction, but use a directed pattern when direction carries business meaning. Cypher introduction · MATCH clause
When should you use CREATE or MERGE?
CREATE makes new nodes or relationships without checking whether matching data already exists; rerunning the same import can create duplicates. MERGE first searches for the specified pattern, reuses it if found, and otherwise creates it. That makes MERGE a useful starting point for rerunnable syncs and incremental imports. But the properties used to match must identify the intended entity. Without a unique identity, distinct records can be conflated or existing duplicates can remain.
The example below protects a stable person ID with a uniqueness constraint, then reuses nodes and the relationship on repeated runs. CREATE may be simpler for a one-time load into a clean, empty database. A uniqueness constraint can take time because existing data is checked, and the user needs the required privilege. Check that IDs are truly unique before adding it. Do not assume MERGE alone solves every duplicate or concurrent-write problem. Cypher CREATE and MERGE · Create constraints
CREATE CONSTRAINT person_id IF NOT EXISTS
FOR (p:Person) REQUIRE p.id IS UNIQUE;
MERGE (a:Person {id: 'u-17'})
SET a.name = 'Mina'
MERGE (b:Person {id: 'u-42'})
SET b.name = 'Jae'
MERGE (a)-[:FOLLOWS]->(b);
MATCH (a:Person {id: 'u-17'})-[:FOLLOWS]->(b:Person)
RETURN b.id, b.name;When might Neo4j fit?
Recommendation discovery, permission inheritance, supply-chain dependencies, or asset-impact paths are candidate uses when the repeated question is “what is connected?” or “which path leads here?” A discovered path is not proof of causation or risk. For example, two accounts sharing a device is a possible association, not proof of fraud; it needs context and review.
| Main question | Consider in a Neo4j graph | A different model may be simpler when… |
|---|---|---|
| What is connected within a few steps? | Define node labels and relationship types/directions | Relations are fixed and queries are mostly key lookups |
| What paths connect entities across many steps? | Bound path length, labels, and result count | The task repeatedly aggregates very broad paths |
| How can an import be safely rerun? | Stable IDs, uniqueness constraints, and MERGE | A clean store receives a one-time load, where CREATE may suffice |
Before adopting Neo4j, sketch representative questions as nodes and relationships; decide each connection’s direction, type, and duplicate meaning; then express it as a Cypher pattern. Indexes and constraints can help find starting nodes and protect data quality, but they do not make broad or deep traversals free. Verify choices against the Neo4j version, edition, deployment, and query plans in use.
Scope and official sources
Neo4j’s official documentation was checked November 23, 2026. The Cypher examples are explanatory and were not run. Feature availability, including constraints, may depend on edition, version, and deployment; check the documentation for the target environment.
[What is a Neo4j graph database?](https://neo4j.com/docs/getting-started/graph-database/)
[What is Cypher?](https://neo4j.com/docs/getting-started/cypher/)
[Cypher core concepts](https://neo4j.com/docs/cypher-manual/current/queries/concepts/)
[`MATCH` clause](https://neo4j.com/docs/cypher-manual/current/clauses/match/)
[`CREATE` and `MERGE`](https://neo4j.com/docs/cypher-manual/current/clauses/create/)
[Create constraints](https://neo4j.com/docs/cypher-manual/current/schema/constraints/create-constraints/)