Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Exploring the Cypher Query
Language through GraphGists
Luanne Misquitta

@luannem
Our Path
Neo4j Cypher ExamplesGraphGists
What if…
Credit: Shantaram Waingankar
Or
Credit: Luanne M.
Or
Credit: Florent Biville
Or
6
Credit: Luanne M.
All you need is…
According to The Beatles
But that’s not why you’re here
What you really need is… a Graph
What is Neo4j?
• A Graph Database
• A labelled property graph
• Nodes with properties and labels (both optional)
• Directe...
What is Neo4j
name:Neo
name: Agent
Smith
name:
Cypher
name:
Morpheus
name:TrinityLoves
Knows
Knows 

{since: 1999}
Knows
K...
Cypher
• Declarative graph query language
• Based on English prose and neat
iconography
• Focuses on 
• What to retrieve f...
Patterns and pictures
Neo Trinity
Loves
Neo loves Trinity
(Neo)-[:LOVES]->(Trinity)
Cypher
Agent
Smith
Knows
Cypher knows ...
Pattern matching
14
MATCH
(me:User {name:’Luanne’})-[f:FRIEND_OF]->(friend)-[:LISTENS_TO]->(artist)!
WHERE NOT (me-[:LISTE...
Example Query Structure
15
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artist...
MATCH
• Allows you to specify patterns that Cypher
will search for in the graph
16
Match
17
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artistCount
!
MATCH (a)-...
Where
• Filters the results
• Adds constraints to the pattern described in
MATCH
18
Where
19
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artistCount
!
MATCH (a)-...
Return
• Returns results
20
Return
21
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artistCount
!
MATCH (a)...
Order By, Limit
• Sort the output
• Return a subset
22
Order By, Limit
23
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artistCount
!
...
WITH
• Manipulate the result sequence before it is
passed on to the following query parts. 
• The manipulations can be of ...
With
25
MATCH (u:User)-[:LISTENS_TO]->(a:Artist)
!
WHERE a.genre=“Rock”
!
WITH u, a, count(a) as artistCount
!
MATCH (a)-[...
GraphGists
What’s a Gist?
27
• A simple way to share snippets of code or
data
• Automatically versioned, forkable, usable
from Git
• ...
Okay, why?
• How do you share your graph model?
• Whiteboard?
• Document?
• How do you demonstrate queries? 
• Need a live...
What’s a GraphGist?
29
• An AsciiDoc file with:
• A graph domain model
• Descriptive text and pictures
• Example queries ag...
GraphGist demos
• Trek and mountaineering routing

http://gist.neo4j.org/?09520d20fbe707951e1b 

@shantaramw
• Organizatio...
Resources
32
Neo4j
http://www.neo4j.org/
!
Explore and create your own GraphGist
http://www.neo4j.org/learn/graphgist
!
Online Train...
Exploring cypher with graph gists
Prochain SlideShare
Chargement dans…5
×

Exploring cypher with graph gists

1 431 vues

Publié le

Talk at the Great Indian Developer Summit(http://www.developermarch.com/developersummit/conference.html) 2014, Bangalore.

Publié dans : Technologie
  • Soyez le premier à commenter

Exploring cypher with graph gists

  1. 1. Exploring the Cypher Query Language through GraphGists Luanne Misquitta
 @luannem
  2. 2. Our Path Neo4j Cypher ExamplesGraphGists
  3. 3. What if… Credit: Shantaram Waingankar
  4. 4. Or Credit: Luanne M.
  5. 5. Or Credit: Florent Biville
  6. 6. Or 6 Credit: Luanne M.
  7. 7. All you need is… According to The Beatles
  8. 8. But that’s not why you’re here
  9. 9. What you really need is… a Graph
  10. 10. 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
  11. 11. What is Neo4j name:Neo name: Agent Smith name: Cypher name: Morpheus name:TrinityLoves Knows Knows 
 {since: 1999} Knows Knows Crew Crew Crew Crew MatrixMatrix
  12. 12. 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
  13. 13. Patterns and pictures Neo Trinity Loves Neo loves Trinity (Neo)-[:LOVES]->(Trinity) Cypher Agent Smith Knows Cypher knows Agent Smith (Cypher)-[:KNOWS]->(Agent Smith)
  14. 14. 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
  15. 15. 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
  16. 16. MATCH • Allows you to specify patterns that Cypher will search for in the graph 16
  17. 17. 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
  18. 18. Where • Filters the results • Adds constraints to the pattern described in MATCH 18
  19. 19. 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
  20. 20. Return • Returns results 20
  21. 21. 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
  22. 22. Order By, Limit • Sort the output • Return a subset 22
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. GraphGists
  27. 27. 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
  28. 28. Okay, why? • How do you share your graph model? • Whiteboard? • Document? • How do you demonstrate queries? • Need a live database? • Modelling is incremental 28
  29. 29. 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
  30. 30. GraphGist demos • Trek and mountaineering routing
 http://gist.neo4j.org/?09520d20fbe707951e1b 
 @shantaramw • Organization learning
 http://gist.neo4j.org/?8021754 
 @luannem • Doctor Finder
 http://gist.neo4j.org/?8748719
 @fbiville • Bombay Railway Routes 
 http://gist.neo4j.org/?8159102
 @luannem 30
  31. 31. Resources
  32. 32. 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

×