Module 4. Following Paths: Exploring Depth and Direction
Course 5. Querying Meaning: Writing Cypher for Insight
Estimated Time: ?? minutes
🧭 Module Objectives
- Use variable-length patterns (
*1..3) to follow multi-step relationships. - Explore indirect or hidden links between nodes.
- Interpret how direction (
-->,<--, or--) affects query meaning. - Combine multiple relationship types to trace more complex paths.
- Understand how “depth” in a graph translates to interpretive distance in humanities research.
From Points to Pathways
In previous modules, you learned how to count and summarize what exists.
Now you’ll learn how to move through it.
Graphs aren’t just collections of nodes — they’re networks of relationships.
Every connection can lead somewhere new, and Cypher lets you travel these routes, step by step or leap by leap, revealing how meaning flows through the data.
The Power of Paths
A path in Neo4j is simply a chain of nodes and relationships. For example(:Person)-[:WROTE_SONG]->(:Song)-[:EVOKES_THEME]->(:Theme)
represents one path that says, "A person wrote a song that evokes a theme."
Cypher can search for such paths and return every matching instance.
Variable-Length Relationships
Sometimes we don't know how many steps connect two ideas. That;s where variable-length syntax comes in:MATCH path = (p:Person)-[*1..3]-(t:Theme)
RETURN path;
—Here, [*1..3] tells Neo4j to explore all paths where a Person and a Theme are connected by 1–3 relationship steps.
Example A – People Connected to “Critique of War” Within 3 Steps
To find all people connected (directly or indirectly) to that theme:MATCH path = (p:Person)-[*1..3]-(t:Theme {name: "Critique of War"})
RETURN DISTINCT p.name;
This explores paths such as:Person → WROTE_SONG → Song → EVOKES_THEME → “Critique of War” ANDPerson → PERFORMS_AS → Artist → CREDITED_ON → Recording → PERFORMANCE_OF → Song → EVOKES_THEME
Interpretation → Shows who is thematically involved, even if indirectly (e.g., performers on recordings that evoke the theme).
Example B – Songs Two Steps Away from an EventMATCH (e:Event {name:"Farm Aid 2025"})
MATCH path = (e)<-[*1..2]-(r:Recording)
MATCH (r)-[:PERFORMANCE_OF]->(s:Song)
RETURN DISTINCT s.title;
Interpretation → This returns songs performed at the event (depth 1)
or songs performed by artists connected to that event through one additional step (depth 2).
Direction Matters
Arrows communicate flow. Reversing them reverses meaning.
| Pattern | Reads as | Interpretation |
|---|---|---|
(p)-[:WROTE_SONG]->(s) |
"Person → Song" | Person wrote song |
(s)<-[:WROTE_SONG]-(p) |
"Song ← Person" | Song was written by person |
(p)--(s) |
"Either direction" | Connection exists, direction ignored |
You can omit arrows while exploring, then reintroduce them for precision once you know what relationships exist.
Example C – Ignoring Direction to Discover LinksMATCH (p:Person {uid:"pers-jesse-wells"})--(x)
RETURN DISTINCT labels(x) AS nodeType, COUNT(x) AS count
ORDER BY count DESC;
Interpretation → Shows whether Jesse connects most to Songs, Recordings, Albums, Artists, Themes, etc.
Example D – Following a Directed ChainMATCH (p:Person {uid:"pers-jesse-wells"})-[:WROTE_SONG]->(s:Song)
MATCH (s)<-[:PERFORMANCE_OF]-(r:Recording)-[:RELEASED_ON]->(a:Album)
RETURN a.title, COUNT(DISTINCT s) AS songsWritten;
Interpretation → Shows the albums Jesse’s written songs appear on, specifying direction at every step, producing clear, interpretable paths.
Combining Relationship Types
You can include multiple relationship types using the | symbol. For example:
MATCH (p:Person {uid:"pers-jesse-wells"})-[:WROTE_SONG|:PERFORMED_ON]->(x)
RETURN DISTINCT labels(x) AS connectedType;
Interpretation → Shows what kinds of creative work Jesse connects to—songs written, recordings performed on, etc.
Capturing the Whole Path
If you assign the pattern to a variable (like path), Neo4j can return the entire route, not just the endpoints. For example:
MATCH path = (p:Person {uid:"pers-jesse-wells"})-[*1..2]->(t:Theme)
RETURN path;
Visualize this result in the graph view: you'll see all nodes and relationships traversed. Each path is a miniature narrative: a story of how one idea leads to another.
Wellespring in Practice
Example E – Tracing Influence through CollaborationMATCH (jesse:Person {uid:"pers-jesse-wells"})-[:PERFORMED_ON]->(rec:Recording)
MATCH (other:Person)-[:PERFORMED_ON]->(rec)
WHERE other <> jesse
RETURN DISTINCT other.name AS collaborator;
Interpretation → Shows people directly connected to Jesse through shared studio work. To include indirect collaborators (friends-of-friends):MATCH (p1:Person {uid:"pers-jesse-wells"})-[:PERFORMED_ON*1..2]->(p2:Person)
WHERE p2 <> p1
RETURN DISTINCT p2.name;
Example F – Themes Reaching Across AlbumsMATCH (t:Theme)<-[:EVOKES_THEME]-(s:Song)
MATCH (s)<-[:PERFORMANCE_OF]-(r:Recording)-[:RELEASED_ON]->(a:Album)
RETURN t.name, COLLECT(DISTINCT a.title) AS albums;
Interpretation → Shows how a theme spans multiple albums—supporting arguments about thematic continuity or development.
Depth as Interpretive Distance
In graphs, depth is a count of steps between nodes.
In interpretation, it reflects conceptual or creative distance.
- Depth 1 — direct influence
“Jesse wrote this song.” - Depth 2 — mediated influence
“Jesse wrote a song that evokes a theme.” - Depth 3+ — cultural ripples
“This theme appears across multiple recordings and artists.”
Thinking in depth helps humanists trace chains of meaning, not just individual links.
Try It Yourself
- Follow all paths (≤ 3 steps) from Jesse Welles to any Theme.
MATCH path = (p:Person {name:"Jesse Welles"})-[*1..3]-(t:Theme)
RETURN DISTINCT t.name; - Find all people connected to Jesse Welles within two steps.
MATCH path =
(p:Person {uid:"pers-jesse-wells"})-[:PERFORMED_ON*1..2]-(others:Person)
WHERE others <> p
RETURN DISTINCT others.name; - Trace albums linked (directly or indirectly) to a particular Theme.
MATCH (t:Theme {name:"Cosmic Imagery"})<-[:EVOKES_THEME]-(s:Song)
MATCH path = (s)<-[:PERFORMANCE_OF]-(r:Recording)-[*1..2]->(a:Album)
RETURN DISTINCT a.title;
Try switching between Graph and Table views to see how visual distance reflects conceptual distance. Try swapping out themes, etc. to see how these kinds of queries can be powerful ways of exploring your data.
Key Takeaways
- A path is a sequence of connected nodes and relationships.
- Variable-length patterns (
[*min..max]) let you explore unknown chains. - Arrows (
-->,<--,--) define meaningful directionality. - Combining relationship types with
|broadens exploration. - Depth in the graph mirrors interpretive distance in humanities reasoning.