Sarvesh Nagarajan. What is Neo4j? Graph Databases Cypher Application Domains.
Exploring cypher with graph gists
-
Upload
luanne-misquitta -
Category
Technology
-
view
114 -
download
2
description
Transcript of Exploring cypher with graph gists
![Page 1: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/1.jpg)
Exploring the Cypher Query Language through GraphGists
Luanne Misquitta @luannem
![Page 2: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/2.jpg)
Our Path
Neo4j Cypher ExamplesGraphGists
![Page 3: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/3.jpg)
What if…
Credit: Shantaram Waingankar
![Page 4: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/4.jpg)
Or
Credit: Luanne M.
![Page 5: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/5.jpg)
Or
Credit: Florent Biville
![Page 6: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/6.jpg)
Or
6Credit: Luanne M.
![Page 7: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/7.jpg)
All you need is…
According to The Beatles
![Page 8: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/8.jpg)
But that’s not why you’re here
![Page 9: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/9.jpg)
What you really need is… a Graph
![Page 10: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/10.jpg)
What is Neo4j?
• A Graph Database • A labelled property graph • Nodes with properties and labels (both optional) • Directed and named relationships with properties
(optional) • ACID • Schema free • Scalable: Billions of nodes and relationships • Fast: More than 2 million traversals per second • Suited for highly connected and complex data
![Page 11: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/11.jpg)
What is Neo4j
name:Neo
name: Agent Smith
name: Cypher
name: Morpheus
name:TrinityLoves
KnowsKnows {since: 1999}
Knows
Knows
CrewCrew
Crew
CrewMatrixMatrix
![Page 12: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/12.jpg)
Cypher
• Declarative graph query language • Based on English prose and neat
iconography • Focuses on
• What to retrieve from the graph and not how to retrieve it
• Pattern matching • Your domain instead of database access
• Humane query language, suitable for developers and operations professionals
![Page 13: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/13.jpg)
Patterns and picturesNeo Trinity
LovesNeo loves Trinity
(Neo)-[:LOVES]->(Trinity)
Cypher Agent Smith
KnowsCypher knows Agent Smith
(Cypher)-[:KNOWS]->(Agent Smith)
![Page 14: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/14.jpg)
Pattern matching
14
MATCH (me:User {name:’Luanne’})-[f:FRIEND_OF]->(friend)-[:LISTENS_TO]->(artist)!WHERE NOT (me-[:LISTENS_TO]->(artist) AND f.similarity>0.7!RETURN artist
Luanne
The Beatles
F1
Aerosmith
F2
Pink Floyd
FRIEND_OF {similarity=0.9}
FRIEND_OF {similarity=0.4}
LISTENS_TO
LISTENS_TO
LISTENS_TOLISTENS_TO
![Page 15: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/15.jpg)
Example Query Structure
15
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 16: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/16.jpg)
MATCH
• Allows you to specify patterns that Cypher will search for in the graph
16
![Page 17: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/17.jpg)
Match
17
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 18: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/18.jpg)
Where
• Filters the results • Adds constraints to the pattern described in
MATCH
18
![Page 19: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/19.jpg)
Where
19
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 20: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/20.jpg)
Return
• Returns results
20
![Page 21: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/21.jpg)
Return
21
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 22: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/22.jpg)
Order By, Limit
• Sort the output • Return a subset
22
![Page 23: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/23.jpg)
Order By, Limit
23
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 24: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/24.jpg)
WITH
• Manipulate the result sequence before it is passed on to the following query parts.
• The manipulations can be of the shape and/or number of entries in the result set.
• Combines queries
24
![Page 25: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/25.jpg)
With
25
MATCH (u:User)-[:LISTENS_TO]->(a:Artist) !WHERE a.genre=“Rock” !WITH u, a, count(a) as artistCount !MATCH (a)-[r:PLAYING_IN]->(city) !WHERE r.ticketsAvailable=true !RETURN u,a,city.name as cityName !ORDER BY cityName LIMIT 5
![Page 26: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/26.jpg)
GraphGists
![Page 27: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/27.jpg)
What’s a Gist?
27
• A simple way to share snippets of code or data
• Automatically versioned, forkable, usable from Git
• Nicely rendered and presented
![Page 28: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/28.jpg)
Okay, why?
• How do you share your graph model? • Whiteboard? • Document? • How do you demonstrate queries? • Need a live database? • Modelling is incremental
28
![Page 29: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/29.jpg)
What’s a GraphGist?
29
• An AsciiDoc file with: • A graph domain model • Descriptive text and pictures • Example queries against the model • Interactive and executable Cypher queries • A Neo4j console for further exploration
• Nicely rendered and presented
![Page 30: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/30.jpg)
GraphGist demos• Trek and mountaineering routing
http://gist.neo4j.org/?09520d20fbe707951e1b @shantaramw
• Organization learninghttp://gist.neo4j.org/?8021754 @luannem
• Doctor Finder http://gist.neo4j.org/?8748719 @fbiville
• Bombay Railway Routes http://gist.neo4j.org/?8159102 @luannem 30
![Page 31: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/31.jpg)
Resources
![Page 32: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/32.jpg)
32
Neo4j http://www.neo4j.org/ !Explore and create your own GraphGist http://www.neo4j.org/learn/graphgist !Online Training http://www.neo4j.org/learn/online_course
Spreading Graph Love
![Page 33: Exploring cypher with graph gists](https://reader034.fdocuments.us/reader034/viewer/2022052321/54c6db784a7959e9078b45af/html5/thumbnails/33.jpg)