Use advanced Cypher on a university collaboration graph (40 researchers, 170 directed edges, 4 relationship types): negative patterns, aggregations, multi-hop, and mixed edge-type matching.
-- Setup: 40 researchers, 170 edges across 4 relationship types
CREATE GRAPH external.research_network.research_network
VERTEX TABLE external.research_network.researchers
ID COLUMN id NODE TYPE COLUMN department NODE NAME COLUMN name
EDGE TABLE external.research_network.collaborations
SOURCE COLUMN src TARGET COLUMN dst
WEIGHT COLUMN weight EDGE TYPE COLUMN collab_type
DIRECTED;
CREATE GRAPHCSR external.research_network.research_network;
-- Negative pattern: isolated researchers (no outgoing edges)
USE external.research_network.research_network
MATCH (n) WHERE NOT (n)-->()
RETURN n.name AS name, n.department AS department, n.rank AS rank
ORDER BY n.name;
-- Cypher aggregation: department h-index statistics
USE external.research_network.research_network
MATCH (n)
RETURN n.department AS dept,
count(n) AS num_researchers,
avg(n.h_index) AS avg_h,
min(n.h_index) AS min_h,
max(n.h_index) AS max_h
ORDER BY avg_h DESC;
-- Directed co-author triangles (edge-type filter with repeated pattern)
USE external.research_network.research_network
MATCH (a)-[:co-author]->(b)-[:co-author]->(c)-[:co-author]->(a)
RETURN a.name AS researcher_a, b.name AS researcher_b, c.name AS researcher_c
ORDER BY a.name, b.name;
-- 2-hop advisor chains
USE external.research_network.research_network
MATCH (a)-[:advisor]->(b)-[:advisor]->(c)
WHERE a <> c
RETURN a.name AS senior, a.rank AS senior_rank,
b.name AS middle, b.rank AS middle_rank,
c.name AS junior, c.rank AS junior_rank
ORDER BY a.name, c.name;
-- Multi-pattern MATCH: advisors who also co-author with their advisee
USE external.research_network.research_network
MATCH (a)-[:advisor]->(b), (a)-[:co-author]->(b)
RETURN a.name AS advisor, a.rank AS advisor_rank,
b.name AS advisee, b.rank AS advisee_rank
ORDER BY a.name;
-- count(DISTINCT) for prolific collaborators
USE external.research_network.research_network
MATCH (a)-[]->(b)
RETURN a.name AS name, a.department AS dept, count(DISTINCT b) AS collaborator_count
ORDER BY collaborator_count DESC, name;
-- Algorithms on a directed heterogeneous graph
USE external.research_network.research_network
CALL algo.pageRank({dampingFactor: 0.85, iterations: 20})
YIELD node_id, score, rank
RETURN node_id, score, rank ORDER BY score DESC;
USE external.research_network.research_network
CALL algo.betweenness() YIELD node_id, centrality, rank
RETURN node_id, centrality, rank ORDER BY centrality DESC;
-- Weakly connected components (directed graph, treated as undirected for CC)
USE external.research_network.research_network
CALL algo.connectedComponents() YIELD node_id, component_id
RETURN component_id, count(*) AS size ORDER BY size DESC;
## When to Use Reach for this demo when you know basic `MATCH (a)-[r]->(b)` but need the full Cypher expressive power: negative patterns (`WHERE NOT (n)-->()`), aggregation pipelines with `WITH`, triangle and advisor-chain patterns, mixed relationship-type queries (same pair of nodes connected by two different edge types), and directed graph algorithms on a heterogeneous edge schema. The university research collaboration dataset deliberately mixes four relationship types, co-author, advisor, committee, reviewer, so you can practice edge-type filtering with `[:advisor]` syntax and multi-pattern MATCH. ## What You Will Learn 1. Negative patterns: `MATCH (n) WHERE NOT (n)-->()` to find sources with no outgoing edges, and `WHERE NOT (n)<--()` to find nodes nobody points to. 2. Cypher aggregation functions: `count`, `avg`, `min`, `max`, `collect`, `count(DISTINCT ...)` combined with `ORDER BY aggregate`. 3. Edge-type filtering in MATCH: `(a)-[:co-author]->(b)-[:co-author]->(c)-[:co-author]->(a)` finds directed co-author triangles; `(a)-[:advisor]->(b)-[:advisor]->(c)` finds advisor chains. 4. Multi-pattern MATCH: `MATCH (a)-[:advisor]->(b), (a)-[:co-author]->(b)` finds pairs of nodes connected by both edge types simultaneously. 5. Running all four core algorithms, pageRank, betweenness, connectedComponents, louvain, on a directed heterogeneous graph, and understanding that on a directed graph connected components return *weakly* connected components by default. ## Prerequisites - Completion of the karate-club basics demo recommended. - Familiarity with `CREATE GRAPH ... DIRECTED` and the `EDGE TYPE COLUMN` clause for heterogeneous edge schemas.