A path expression chains node and edge patterns sequentially. A valid path pattern must alternate between nodes and edges, starting and ending with a node pattern.
Chaining Elements:
Match paths starting from a wizard named "Harry", leading to a spell via Teaches:
(:Wizard {name: "Harry"})-[:Teaches]->(:Spell)
Find wizards who share a mutual knows-connection with "Harry" and "Hermione", binding the mutual friend to friend:
(:Wizard {name: "Harry"})-[:Knows]->(friend:Wizard)<-[knows]-(:Wizard {name: "Hermione"})
Ring and Cycle Structures:
You can reuse a node variable at different points in a path pattern to enforce cycle constraints. This query finds a closed alliance loop starting and ending at the same wizard w:
(w:Wizard)-[:AlliedWith]->(:Wizard)-[:AlliedWith]->(w)