GraphGist for Mark Needhams Football Domain Examples
CREATE (arsenal:Team {name: "Arsenal"})
CREATE (manUtd:Team {name: "Manchester United"})
CREATE (game:Game {name: "Arsenal vs Man Utd"})
CREATE (game)-[:home_team]->(manUtd)
CREATE (game)-[:away_team]->(arsenal)
MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game
MATCH (game:Game)-[:home_team]->(home:Team),
(game)-[:away_team]->(away)
WHERE home.name = "Manchester United"
AND away.name = "Arsenal"
CREATE (rvp:Player {name: "Robin van Persie"})
CREATE (rvp)-[:played]->(stats {goals: 1})
CREATE (stats)-[:in]->(game)
CREATE (stats)-[:for]->(home)
RETURN rvp, stats
MATCH (player:Player)-[:played]->(stats)
RETURN player.name,
SUM(stats.goals) AS goals
ORDER BY goals DESC
LIMIT 10
Let’s look at the cypher patterns first
(:Player)-[:played]->(playerStats) (playerStats)-[:for]->(:Team) (:Player)-[:comes_from]->(:Country)
Use them to add an example to the graph
CREATE (c:Country {code:"NL"})
WITH c
MATCH (p:Player {name:"Robin van Persie"})
CREATE (c)<-[:comes_from]-(p)
And then build the query from those patterns.
MATCH (player:Player)-[:comes_from]->(country),
(player)-[:played]->(stats)-[:for]->(team)
WHERE country.code = "NL"
AND team.name = "Manchester United"
RETURN player.name, COUNT(player) AS count