Cypher
By Neo4j
Cypher is a declarative query language created by Neo4j for querying and updating property graph databases. It uses an ASCII-art-like syntax to describe patterns of nodes and relationships directly in a query, letting developers express…
Definition
Cypher is a declarative query language created by Neo4j for querying and updating property graph databases. It uses an ASCII-art-like syntax to describe patterns of nodes and relationships directly in a query, letting developers express graph traversals such as finding connected paths or shortest routes without writing manual traversal code. Cypher is the primary query language for the Neo4j graph database and has been adopted as the basis for the openCypher project and the ISO GQL graph query standard.
Overview
Cypher was created by Neo4j to solve a specific readability problem in graph querying: expressing multi-hop relationships and pattern matching in SQL or general-purpose code tends to require verbose joins or explicit traversal logic, whereas graphs are naturally described as networks of connected nodes. Cypher's designers built a syntax that visually resembles the graph structure it queries, using parentheses for nodes and arrows for relationships, so a query reads similarly to how a person would sketch the pattern on paper. Mechanically, a Cypher query typically starts with a MATCH clause describing a pattern of nodes and relationships, optionally filtered with a WHERE clause, and concludes with a RETURN clause specifying which matched elements to output. The query engine searches the underlying property graph for subgraphs matching the pattern, binding variables to actual nodes and relationships found, and additional clauses like CREATE, MERGE, and DELETE let the same language update graph data rather than only read it, all executed against Neo4j's native graph storage engine. Cypher differs from SPARQL in that it targets property graphs, where nodes and relationships can carry arbitrary key-value properties, rather than RDF's triple-based subject-predicate-object model and its associated ontology standards. It also differs from Gremlin, a more imperative, step-based graph traversal language associated with Apache TinkerPop, in that Cypher's declarative pattern-matching style is generally considered more approachable for developers coming from SQL. In practice, Cypher is used to build applications involving fraud detection, recommendation engines, network and IT infrastructure mapping, and knowledge graphs, wherever relationships between entities are as important as the entities themselves. Developers embed Cypher queries in application code through Neo4j drivers, and data engineers use it for both ad hoc exploration of graph data and building production queries that traverse multiple relationship hops efficiently. Cypher's tight association with Neo4j has historically limited portability, though the openCypher initiative and its influence on the ISO GQL standard have broadened its reach to other graph databases. It is not designed for tabular, non-relational analytics the way SQL is, and teams without genuinely graph-shaped data may find a relational or document database simpler to operate. Teams adopt Cypher and a graph database specifically when queries are dominated by relationship traversal, and stick with SQL when data is naturally tabular. Migrating an existing relational dataset into a property graph also requires rethinking the data model around nodes and relationships rather than rows and foreign keys, which is a real up-front cost that teams should weigh against the traversal performance gains before committing to the switch.
Key Features
- ASCII-art syntax representing nodes and relationships visually
- Declarative MATCH and RETURN clauses for pattern-based queries
- Supports creating, updating, and deleting graph data, not just reads
- Native to the Neo4j graph database's storage and execution engine
- Basis for the openCypher project shared across other graph databases
- Influenced the ISO GQL international graph query language standard
- Efficient multi-hop relationship traversal without manual join logic
- Aggregation and path-finding functions built into the language