Cypher is a declarative query language specifically designed for interacting with graph databases in the Neo4j ecosystem. With its intuitive and expressive syntax, Cypher enables users to efficiently traverse and manipulate graph structures using a combination of pattern matching and graph traversal techniques, making it a popular choice for developers and data scientists working with graph-based data models.
PuppyGraph provides support for openCypher (version 9), an open-source implementation of Cypher.
Following the Explore the Example Graph guide, we already setup a demo modern graph data with PuppyGraph that can be used for the rest of the document as an example. You may also use your own graph data.
Hello World
Here are some basic examples of Cypher queries:
MATCH (v) RETURN v all vertexes.
MATCH ()-[e]->() RETURN e all edges.
MATCH (v) RETURN count(v) total number of vertexes.
MATCH ()-[e]->() RETURN count(e) total number of (directed) edges.
MATCH ()-[e]-() RETURN count(e) total number of edges while direction is ignored. An edge (a)-[e]->(b) is counted twice as (a,b) and (b,a) .
Note that in a pattern, an edge is only used once. So marko is not his own co-creator. See Uniqueness section of openCypher (version 9) for more information.
Variable-length pattern matching
Here is another query to get marko's co-creators. The direction of edges is ignored.
puppy-cypher> :> MATCH ({name: 'marko'})-[:knows]->(v) WITH v MATCH (v)-[:created]->(x) RETURN v.name AS otherPerson, x.name AS Software
==>[otherPerson:josh,Software:ripple]==>[otherPerson:josh,Software:lop]
We also use AS to rename the results here.
Official Specification
For detailed Cypher language specification and more resources, please refer to the openCypher official website.