Cypher is a graph query language for labeled-property graphs. Its ASCII-art patterns make nodes, relationships, labels, properties, and directions readable in a compact query form. Use it to create, find, transform, and analyze graph data. section 2.0 section 2.2
Write a node in parentheses. Add a label after a colon and properties as key-value pairs in braces: (:Person {name:"Thomas"}). Give it a variable, such as (thomas:Person), when later parts of the same statement must refer to it. section 3.0
Write a relationship in square brackets between its adjacent nodes: ()-[:RELATIONSHIP]->(). Relationship types follow a colon, properties go in braces, and arrows express direction. Omitting the arrow depicts an undirected pattern, although Neo4j stores relationships as directed. section 2.2 section 3.4
Core clauses support a practical query workflow:
- CREATE adds graph data; MATCH identifies existing graph patterns. section 3.4
- WHERE filters matches or intermediate rows; OPTIONAL MATCH preserves other returned variables when a pattern is absent. section 3.4
- WITH selects, filters, aggregates, paginates, or limits intermediate rows. section 3.4
- SET and REMOVE change properties or labels; DELETE removes graph elements, while DETACH DELETE removes a connected node. section 3.4
- MERGE ensures a pattern exists, supporting idempotent imports and automatic deduplication. section 3.4
Visualize follower relationships
Bind a matched path to p, return it, and limit the result to a manageable sample. A path is a sequence of connected nodes and relationships and can be referenced with a variable like nodes and relationships. section 4.1
Listing 4.1 Generated Cypher query that visualizes a sample of 25 FOLLOWS relationships
MATCH p=()-[r :FOLLOWS]->() RETURN p LIMIT 25;
This query matches FOLLOWS relationships, returns each matched path, and limits the visualization to 25 examples. section 4.1
Count hashtag co-occurrences
Match two Tag nodes attached to the same tweet, use id(h1) < id(h2) to avoid duplicate pairs, count shared tweets, then order and limit the results. The count becomes the relationship weight in a co-occurrence network. section 7.2
Listing 7.9 Examining the top five most co-occurring pairs of hashtags
MATCH (h1:Tag)<-[:HAS_TAG]-()-[:HAS_TAG]->(h2:Tag) WHERE id(h1) < id(h2) #1 WITH h1,h2,count(*) AS cooccurrences ORDER BY cooccurrences DESC LIMIT 5 RETURN h1.id AS tag1, h2.id AS tag2, cooccurrences
The listing combines MATCH, WHERE, WITH, count(), ORDER BY, LIMIT, and RETURN to rank hashtag pairs by co-occurrence. section 7.2



