Cypher
cypher
- Query Language for Neo4j
- Case-sensitive SQL like syntax, but for Graphs
- Nodes:
()
- Relationships:
[]
- Paths:
(n)--(m)
or ()-[r {name: $value}]->()
or ()<-[]-()
- Returns result in Graph or Tabular format
Patterns
Pattern | Description |
---|
(n)-[r]->(m) | Bind to relation r |
(n)-[*]->(m) | Variable length relationships |
(n)-[*1..5]->(m) | Variable length path of 1-5 relationships |
(n)-[*0..]->(m) | Recursive Relationship |
(n)-[:KNOWS|:LOVES]-(m) | match Relationship Type using OR |
(me:Me:User) | match multiple Labels using AND |
- Supports Aliases in Return clause:
MATCH(o:Org) RETURN o.name as OrgName
- Short Where Clause:
MATCH (p:Person{name: 'Frank'}) RETURN p.name
- Avoid duplicates with
RETURN DISTINCT
- Optional Match with
OPTIONAL MATCH(o:Org)
- Similar to SQL joins, Cypher has
*0..
- Negate Pattern with
NOT EXISTS( (n)--(m) )
or isEmpty( (n)-->(m) )
- Remove Nodes WITHOUT Relationships
MATCH(n) DELETE n
- Remove Nodes WITH Relationships
MATCH(n) DETACH DELETE n
- Create or Update with
MERGE (u:User{name:"fab"})
- Inequality Comparison with
<>
Examples