Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to neo4j - a hands-on crash course

Intro to Neo4j with some hands-.on experience

  • Login to see the comments

Introduction to neo4j - a hands-on crash course

  1. 1. Introduction to Neo4j - a hands-on crash course Lju Lazarevic lju@neo4j.com @ellazal community.neo4j.com
  2. 2. In this session We will cover: • What is a graph and why we need them • Spotting good graph scenarios • Property graph database anatomy and introduction to Cypher • Hands-on: the movie graph on sandbox • sandbox.neo4j.com • Continuing your graph journey
  3. 3. What is a graph?
  4. 4. A graph is... ...a set of discrete objects, each of which has some set of relationships with the other objects Seven Bridges of Konigsberg problem. Leonhard Euler, 1735
  5. 5. Anything can be a graph the Internet a water molecule H O H
  6. 6. Why do we need graphs?
  7. 7. Reality seldom comes in discrete tables Customer Beverage Mapping Action CI Name BI Name AI Type CI BI AIProblems are best understood with a representation of reality Reality is often about things being connected to other things drinks in store A graph provides a better approximation of reality Customer Coffee DRINKS Reality does not stop at the border of a data silo Customer Product Order 19 Jason 32 Ann 91 Dan 11 Filter 21 Latte 31 Flat W. 01 Buy 04 Preord. 09 Drink 91 21 01 91 21 09 32 11 04
  8. 8. Follow the flow - buying trainers
  9. 9. Panama papers: simple model, powerful outcome
  10. 10. The Panama papers data model...
  11. 11. Roses are red, facebook is blue, No mutual friends, So who are you?
  12. 12. Friends of friends ...or co-actors of co-actors
  13. 13. What are good graph scenarios?
  14. 14. Scenario 1: Does our problem involve understanding relationships between entities? Identifying good graph scenarios ● Recommendations ● Fraud detection ● Finding duplicates ● Data lineage
  15. 15. Scenario 2: Does the problem involve a lot of self-referencing to the same type of entity? Identifying good graph scenarios ● Organisational hierarchies ● Access management ● Social influencers ● Friends of friends
  16. 16. Scenario 3: Does the problem explore relationships of varying or unknown depth? Identifying good graph scenarios ● Supply chain visibility ● Bill of Materials ● Network management
  17. 17. Scenario 4: Does our problem involve discovering lots of different routes or paths? Identifying good graph scenarios ● Logistics and routing ● Infrastructure management ● Dependency tracing
  18. 18. So what does a (property) graph look like?
  19. 19. Node (Vertex) ● The main data element from which graphs are constructed Graph components Jane car
  20. 20. Graph components Node (Vertex) ● The main data element from which graphs are constructed Relationship (Edge) ● A link between two nodes. Has: ○ Direction ○ Type ● A node without relationships is permitted. A relationship without nodes is not Jane carOWNS
  21. 21. Label property graph database Node (Vertex) Relationship (Edge) OWNS
  22. 22. Label property graph database Node (Vertex) Relationship (Edge) :Person :CarOWNS Label ● Define node category (optional)
  23. 23. Label property graph database Node (Vertex) Relationship (Edge) :Person :CarOWNS Label ● Define node category (optional) ● Can have more than one :Asset
  24. 24. Node (Vertex) Relationship (Edge) :Person :CarOWNS Label ● Define node category (optional) ● Can have more than one Properties ● Enrich a node or relationship ● No need for nulls! name: Jane make: Volvo model: V60 since: 2018 :Asset Label property graph database
  25. 25. How do I query the graph?
  26. 26. 27  Cypher
  27. 27. 28  Cypher
  28. 28. 29  Cypher ツ
  29. 29. Use MATCH to retrieve nodes //Match all nodes MATCH (n) RETURN n;
  30. 30. Use MATCH to retrieve nodes //Match all nodes MATCH (n) RETURN n; //Match all nodes with a Person label MATCH (n:Person) RETURN n;
  31. 31. Use MATCH to retrieve nodes //Match all nodes MATCH (n) RETURN n; //Match all nodes with a Person label MATCH (n:Person) RETURN n; //Match all nodes with a Person label and property name is "Tom Hanks" MATCH (n:Person {name: "Tom Hanks"}) RETURN n;
  32. 32. //Return nodes with label Person and name property is "Tom Hanks" - Inline MATCH (p:Person {name: "Tom Hanks"}) //Only works with exact matches RETURN p; Use MATCH and properties to retrieve nodes
  33. 33. //Return nodes with label Person and name property is "Tom Hanks" - Inline MATCH (p:Person {name: "Tom Hanks"}) //Only works with exact matches RETURN p; //Return nodes with label Person and name property equals "Tom Hanks" MATCH (p:Person) WHERE p.name = "Tom Hanks" RETURN p; Use MATCH and properties to retrieve nodes
  34. 34. //Return nodes with label Person and name property is "Tom Hanks" - Inline MATCH (p:Person {name: "Tom Hanks"}) //Only works with exact matches RETURN p; //Return nodes with label Person and name property equals "Tom Hanks" MATCH (p:Person) WHERE p.name = "Tom Hanks" RETURN p; //Return nodes with label Movie, released property is between 1991 and 1999 MATCH (m:Movie) WHERE m.released > 1990 AND m.released < 2000 RETURN m; Use MATCH and properties to retrieve nodes
  35. 35. Extending the MATCH
  36. 36. //Find all the movies Tom Hanks acted in MATCH (:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m:Movie) RETURN m.title; Extending the MATCH
  37. 37. //Find all the movies Tom Hanks acted in MATCH (:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m:Movie) RETURN m.title; //Find all the movies Tom Hanks directed and order by latest movie MATCH (:Person {name:"Tom Hanks"})-[:DIRECTED]->(m:Movie) RETURN m.title, m.released ORDER BY m.released DESC; Extending the MATCH
  38. 38. //Find all the movies Tom Hanks acted in MATCH (:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m:Movie) RETURN m.title; //Find all the movies Tom Hanks directed and order by latest movie MATCH (:Person {name:"Tom Hanks"})-[:DIRECTED]->(m:Movie) RETURN m.title, m.released ORDER BY m.released DESC; //Find all of the co-actors Tom Hanks have worked with MATCH (:Person {name:"Tom Hanks"})-->(:Movie)<-[:ACTED_IN]-(coActor:Person) Extending the MATCH
  39. 39. //Create a person node called "Tom Hanks" CREATE (p:Person {name:"Tom Hanks"}); CREATE
  40. 40. //Create a person node called "Tom Hanks" CREATE (p:Person {name:"Tom Hanks"}); //Create an ACTED_IN relationship between "Tom Hanks" and "Apollo 13" MATCH (p:Person {name:"Tom Hanks"}), (m:Movie {title:"Apollo 13"}) CREATE (p)-[:ACTED_IN]->(m); CREATE
  41. 41. //Create a person node called "Tom Hanks" CREATE (p:Person {name:"Tom Hanks"}); //Create an ACTED_IN relationship between "Tom Hanks" and "Apollo 13" MATCH (p:Person {name:"Tom Hanks"}), (m:Movie {title:"Apollo 13"}) CREATE (p)-[:ACTED_IN]->(m); //Create the pattern of "Tom Hanks" ACTED_IN "Apollo 13" //This will create the entire pattern, nodes and all! CREATE (:Person {name:"Tom Hanks")-[:ACTED_IN]->(:Movie {title:"Apollo 13}); CREATE
  42. 42. Time to have a go! We are going to: • Go to sandbox.neo4j.com • Sign in • Select "Blank sandbox" and click Launch Project We’ll all have a go together :)
  43. 43. So how do I continue my graph journey?
  44. 44. Free book: neo4j.com/graph-databases-book Free online training and certification: neo4j.com/graphacademy/online-training How to, best practices and customer stories: youtube.com/neo4j
  45. 45. But you can still have a go at these fun challenges at your own pace! • Modelling a barbecue • Exploring a museum collection • Solving a murder mystery • Virtually visiting Central Park Start here: r.neo4j.com/son-week1 Summer of Nodes is over...
  46. 46. Ljubica Lazarevic Developer Relations Advocate @ElLazal lju@neo4j.com Join the conversation at community.neo4j.com

×