1 of 74

Introduction to Neo4j - �a hands-on crash course

dev.neo4j.com/forum

dev.neo4j.com/chat

Neo4j, Inc. CC BY-SA 4.0

2 of 74

This is an interactive session!

Tell us where you're from!

And please ask Questions

as we go along!

In any of the chats

Neo4j, Inc. CC BY-SA 4.0

3 of 74

In this session

We will cover:

  • What is a graph and why they are amazing
  • Spotting good graph scenarios
  • Property graph database anatomy and introduction to Cypher
  • Hands-on: the northwind graph on Neo4j AuraDB Free
    • console.neo4j.io
  • Continuing your graph journey

Useful reference: https://dev.neo4j.com/rdbms-gdb

Neo4j, Inc. CC BY-SA 4.0

4 of 74

Because it takes a few minutes to launch

Let's get started on

AuraDB Free

neo4j.com/aura

Ask in the chat if something doesn't work!

Neo4j, Inc. CC BY-SA 4.0

5 of 74

Time to have a go! With AuraDB Free

We are going to:

  1. Go to console.neo4j.io
  2. Register (need to verify email)
  3. Login
  4. Select Top Left "Start Here" Database
  5. Click “Create Database”
  6. Download the generated credentials - keep it safe!�(The .env file can be opened with any text editor)

Neo4j, Inc. CC BY-SA 4.0

6 of 74

Neo4j, Inc. CC BY-SA 4.0

7 of 74

Neo4j, Inc. CC BY-SA 4.0

8 of 74

Neo4j, Inc. CC BY-SA 4.0

9 of 74

Neo4j, Inc. CC BY-SA 4.0

10 of 74

Neo4j, Inc. CC BY-SA 4.0

11 of 74

What is a graph?

versus

Neo4j, Inc. CC BY-SA 4.0

12 of 74

A graph is...

...a set of discrete entities, each of which has some set of relationships with the other entities

Seven Bridges of Konigsberg problem. Leonhard Euler, 1735

Neo4j, Inc. CC BY-SA 4.0

13 of 74

Anything can be a graph - do you have examples too?

the Internet

a water molecule

H

O

H

Neo4j, Inc. CC BY-SA 4.0

14 of 74

Why are graphs amazing?

Neo4j, Inc. CC BY-SA 4.0

15 of 74

Neo4j, Inc. CC BY-SA 4.0

16 of 74

Follow the flow - buying trainers

Neo4j, Inc. CC BY-SA 4.0

17 of 74

Panama, paradise, pandora papers:

simple model, powerful outcome

Neo4j, Inc. CC BY-SA 4.0

18 of 74

18

The ICIJ Investigations data model...

Neo4j, Inc. CC BY-SA 4.0

19 of 74

Friends of friends

...or co-actors of co-actors

Neo4j, Inc. CC BY-SA 4.0

20 of 74

What are good graph scenarios?

Neo4j, Inc. CC BY-SA 4.0

21 of 74

Identifying good graph scenarios

Scenario 1: Does our problem involve understanding relationships between entities?

  • Recommendations
  • Fraud detection
  • Finding duplicates
  • Data lineage
  • Social Networks

Neo4j, Inc. CC BY-SA 4.0

22 of 74

Identifying good graph scenarios

Scenario 2: Does the problem involve a lot of self-referencing to the same type of entity?

  • Organisational hierarchies
  • Access management
  • Social influencers
  • Friends of friends

Neo4j, Inc. CC BY-SA 4.0

23 of 74

Identifying good graph scenarios

Scenario 3: Does the problem explore relationships of varying or unknown depth?

  • Supply chain visibility
  • Bill of Materials
  • Network management
  • Routing

Neo4j, Inc. CC BY-SA 4.0

24 of 74

Identifying good graph scenarios

Scenario 4: Does our problem involve discovering lots of different routes or paths?

  • Logistics and routing
  • Infrastructure management
  • Dependency tracing

Neo4j, Inc. CC BY-SA 4.0

25 of 74

So what does a (property) graph look like?

Neo4j, Inc. CC BY-SA 4.0

26 of 74

Graph components

26

Node (Vertex)

  • The main data element from which graphs are constructed �

Jane

bike

Neo4j, Inc. CC BY-SA 4.0

27 of 74

Graph components

27

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

OWNS

bike

Neo4j, Inc. CC BY-SA 4.0

28 of 74

Property graph database

28

Node (Vertex)

Relationship (Edge)

OWNS

Neo4j, Inc. CC BY-SA 4.0

29 of 74

Property graph database

29

Node (Vertex)

Relationship (Edge)

:Person

:Bike

OWNS

Label

  • Define node role (optional)

Neo4j, Inc. CC BY-SA 4.0

30 of 74

Property graph database

30

Node (Vertex)

Relationship (Edge)

:Person

:Vehicle�:Bike

OWNS

Label

  • Define node role (optional)
  • Can have more than one

Neo4j, Inc. CC BY-SA 4.0

31 of 74

Property graph database

31

Node (Vertex)

Relationship (Edge)

:Person

OWNS

Label

  • Define node role (optional)
  • Can have more than one

Properties

  • Enrich a node or relationship
  • No need for nulls!

name: Jane

make: Specialized

model: Crux Pro

since: 2018

:Vehicle�:Bike

Neo4j, Inc. CC BY-SA 4.0

32 of 74

Retail Dataset - Northwind

Steps

  1. Model
  2. Import
  3. Explore
  4. Query
  5. Build

Neo4j, Inc. CC BY-SA 4.0

33 of 74

Steps

  • Model
  • Import
  • Explore
  • Query
  • Build

Neo4j, Inc. CC BY-SA 4.0

34 of 74

Draw a graph model

Model

  1. [Add Files]
  2. Add Nodes
    1. set label
    2. add properties
    3. select identity
  3. Add Relationships
    • connect nodes
    • set name
    • optional properties

Neo4j, Inc. CC BY-SA 4.0

35 of 74

Map source data to your graph

Map

  • Add Files
  • Map data to node properties
  • Map to relationships (via identifiers)

Neo4j, Inc. CC BY-SA 4.0

36 of 74

Map source data to your graph

Map

  • Add Files
  • Map data to node properties
  • Map to relationships (via identifiers)

Neo4j, Inc. CC BY-SA 4.0

37 of 74

Draw Graph Model

Neo4j, Inc. CC BY-SA 4.0

38 of 74

Preview and Import your data

Import

  • Run Preview
  • Explore the graph (nodes, rels, properties)
  • Run Import
    • Fix any bugs and retry
  • Import Summary
    • rows, counts created
    • statements for constraints and import
  • Go to Explore

Neo4j, Inc. CC BY-SA 4.0

39 of 74

Import Add Files + Map

Neo4j, Inc. CC BY-SA 4.0

40 of 74

Import Map

Neo4j, Inc. CC BY-SA 4.0

41 of 74

Import �Preview

Neo4j, Inc. CC BY-SA 4.0

42 of 74

Import Results

Neo4j, Inc. CC BY-SA 4.0

43 of 74

Preview and Import your data

Explore

  • Run Preview
  • Explore the graph (nodes, rels, properties)
  • Run Import
    • Fix any bugs and retry
  • Import Summary
    • rows, counts created
    • statements for constraints and import
  • Go to Explore

Neo4j, Inc. CC BY-SA 4.0

44 of 74

Explore - Show me a Graph

Neo4j, Inc. CC BY-SA 4.0

45 of 74

Explore Path

Neo4j, Inc. CC BY-SA 4.0

46 of 74

Explore Path

Neo4j, Inc. CC BY-SA 4.0

47 of 74

Write Queries

Query

  • A Graph Console
  • Metadata Sidebar
  • Write your query
    • more queries
  • Visualize results as graph
    • explore, properties, style the graph
  • Visualize as table
  • Favorites

Neo4j, Inc. CC BY-SA 4.0

48 of 74

And now query the graph together!

Neo4j, Inc. CC BY-SA 4.0

49 of 74

Cypher

A pattern-matching query language made for graphs

49

Neo4j, Inc. CC BY-SA 4.0

50 of 74

Cypher

A pattern matching query language made for graphs�

  • Declarative
  • Expressive
  • Pattern-Matching

50

Neo4j, Inc. CC BY-SA 4.0

51 of 74

Cypher

A pattern matching query language made for graphs�

  • Declarative
  • Expressive
  • Pattern Matching

With ASCII ART ¯\_(ツ)_/¯

51

Neo4j, Inc. CC BY-SA 4.0

52 of 74

dev.neo4j.com/refcard

Neo4j, Inc. CC BY-SA 4.0

53 of 74

Use MATCH to retrieve nodes

//Match all nodes with a Product label

MATCH (n:Product)

RETURN n;

Neo4j, Inc. CC BY-SA 4.0

54 of 74

Use MATCH to retrieve nodes

//Match all nodes with a Person label

MATCH (n:Product)

RETURN n;

��//Match all nodes with a Product label and property productName is "Chai"

MATCH (n:Product {name: "Chai"})

RETURN n;

Neo4j, Inc. CC BY-SA 4.0

55 of 74

Use MATCH and properties to retrieve nodes

//Return nodes with label Product and productName property is "Chai" - Inline

MATCH (p:Product {productName: "Chai"}) //Only works with exact matches

RETURN p;

Neo4j, Inc. CC BY-SA 4.0

56 of 74

Use MATCH and properties to retrieve nodes

//Return nodes with label Product and productName property is "Chai" - Inline

MATCH (p:Product {productName: "Chai"}) //Only works with exact matches

RETURN p;

//Return nodes with label Product and productName property is "Chai"

MATCH (p:Product)

WHERE p.productName = "Chai"

RETURN p;

Neo4j, Inc. CC BY-SA 4.0

57 of 74

Use MATCH and properties to retrieve nodes

//Return nodes with label Product and productName property is "Chai" - Inline

MATCH (p:Product {productName: "Chai"}) //Only works with exact matches

RETURN p;

//Return nodes with label Product and productName property is "Chai"

MATCH (p:Product)

WHERE p.productName = "Chai"

RETURN p;

//Return nodes with label Product, unitPrice property is between 10 and 20

MATCH (p:Product)

WHERE 10 < p.unitPrice < 20

RETURN p;

Neo4j, Inc. CC BY-SA 4.0

58 of 74

Extending the MATCH

//Find all the movies Tom Hanks is connected to

MATCH (:Product {productName:"Chai"})--(c:Category)

RETURN c.categoryName;

Neo4j, Inc. CC BY-SA 4.0

59 of 74

Extending the MATCH

//Find all the movies Tom Hanks is connected to

MATCH (:Product {productName:"Chai"})--(c:Category)

RETURN c.categoryName;

//Find all the products that are in the same category as Chai and return ordered by unitPrice descending

MATCH (:Product {productName:"Chai"})-[:PART_OF]->(c:Category)� <-[:PART_OF]-(p2:Product)

RETURN c.categoryName, p2.productName ORDER BY p2.unitPrice DESC;

Neo4j, Inc. CC BY-SA 4.0

60 of 74

MERGE

//Create a product node called "Cheese"

MERGE (p:Product {productName:"Cheese"});

Neo4j, Inc. CC BY-SA 4.0

61 of 74

MERGE

//Create a product node called "Cheese"

MERGE (p:Product {productName:"Cheese"});

//Create an PART_OF relationship between "Cheese" and "Dairy Products"

MATCH (p:Product {productName:"Cheese"}),

(c:Category {categoryName:"Dairy Products"})

MERGE (p)-[:PART_OF]->(c);

Neo4j, Inc. CC BY-SA 4.0

62 of 74

Nodes and relationships at a glance

Description

Node

Relationship

Generic

()

-- --> -[]-

With a reference

(n)

-[r]-

With a node label or rel type

(:Product)

-[:PART_OF]-

With a label/type and an inline property

(:Product {name: 'Chai'})

-[:PART_OF {since: '2021'}]-

With a variable, label/type and an inline property

(p:Product {name: 'Chai'})

-[r:PART_OF {since: '2021'}]-

Neo4j, Inc. CC BY-SA 4.0

63 of 74

Query - Sidebar

Neo4j, Inc. CC BY-SA 4.0

64 of 74

Query - Pattern

Neo4j, Inc. CC BY-SA 4.0

65 of 74

Query - Table

Neo4j, Inc. CC BY-SA 4.0

66 of 74

Build a GraphQL API

Build

  • Use GraphQL Toolbox
  • Infer a GraphQL Schema
    • clean up a bit
  • Derive an API
  • API Queries

Neo4j, Inc. CC BY-SA 4.0

67 of 74

What Is GraphQL?

GraphQL is an API query language and runtime for fulfilling those queries.

GraphQL uses a type system to define the data available in the API, including what entities and attributes (types and fields in GraphQL parlance) exist and how types are connected (the data graph).

GraphQL operations (queries, mutations, or subscriptions) specify an entry-point and a traversal of the data graph (the selection set) which defines what fields to be returned by the operation.

Neo4j, Inc. CC BY-SA 4.0

68 of 74

GraphQL Toolbox - Type Definition

Neo4j, Inc. CC BY-SA 4.0

69 of 74

GraphQL Toolbox - Query

Neo4j, Inc. CC BY-SA 4.0

70 of 74

What Else is There?

Neo4j, Inc. CC BY-SA 4.0

71 of 74

Connectors

What else is there?

Drivers

Data Science

Libraries / Integrations

  • Spark
  • Kafka
  • JDBC
  • Python
  • JavaScript
  • Java
  • .Net
  • Go
  • Graph Data Science Library
  • Graph Data Science Python Client
  • Bloom Visualization
  • neo4j/graphql
  • Spring Data Neo4j
  • neosemantics (RDF)
  • APOC (utility)
  • NeoDash (dashboard)

Neo4j, Inc. CC BY-SA 4.0

72 of 74

So how do I continue my graph journey?

Neo4j, Inc. CC BY-SA 4.0

73 of 74

Continue your journey

Free online training and certification:

  • dev.neo4j.com/learn
  • dev.neo4j.com/datasets
  • neo4j.com/developer

How to, best practices, hands on and community stories:

  • dev.neo4j.com/videos

Come say hello :)

  • dev.neo4j.com/chat
  • dev.neo4j.com/forum

Neo4j, Inc. CC BY-SA 4.0

Neo4j, Inc. CC BY-SA 4.0

74 of 74

Stackoverflow Demo

:play auradb/stackoverflow

Neo4j, Inc. CC BY-SA 4.0