Introduction to Neo4j - �a hands-on crash course
dev.neo4j.com/forum
dev.neo4j.com/chat
Neo4j, Inc. CC BY-SA 4.0
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
In this session
We will cover:
Useful reference: https://dev.neo4j.com/rdbms-gdb
Neo4j, Inc. CC BY-SA 4.0
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
Time to have a go! With AuraDB Free
We are going to:
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
What is a graph?
versus
Neo4j, Inc. CC BY-SA 4.0
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
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
Why are graphs amazing?
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Follow the flow - buying trainers
Neo4j, Inc. CC BY-SA 4.0
Panama, paradise, pandora papers:
simple model, powerful outcome
Neo4j, Inc. CC BY-SA 4.0
18
The ICIJ Investigations data model...
Neo4j, Inc. CC BY-SA 4.0
Friends of friends
...or co-actors of co-actors
Neo4j, Inc. CC BY-SA 4.0
What are good graph scenarios?
Neo4j, Inc. CC BY-SA 4.0
Identifying good graph scenarios
Scenario 1: Does our problem involve understanding relationships between entities?
Neo4j, Inc. CC BY-SA 4.0
Identifying good graph scenarios
Scenario 2: Does the problem involve a lot of self-referencing to the same type of entity?
Neo4j, Inc. CC BY-SA 4.0
Identifying good graph scenarios
Scenario 3: Does the problem explore relationships of varying or unknown depth?
Neo4j, Inc. CC BY-SA 4.0
Identifying good graph scenarios
Scenario 4: Does our problem involve discovering lots of different routes or paths?
Neo4j, Inc. CC BY-SA 4.0
So what does a (property) graph look like?
Neo4j, Inc. CC BY-SA 4.0
Graph components
26
Node (Vertex)
Jane
bike
Neo4j, Inc. CC BY-SA 4.0
Graph components
27
Node (Vertex)
Relationship (Edge)
Jane
OWNS
bike
Neo4j, Inc. CC BY-SA 4.0
Property graph database
28
Node (Vertex)
Relationship (Edge)
OWNS
Neo4j, Inc. CC BY-SA 4.0
Property graph database
29
Node (Vertex)
Relationship (Edge)
:Person
:Bike
OWNS
Label
Neo4j, Inc. CC BY-SA 4.0
Property graph database
30
Node (Vertex)
Relationship (Edge)
:Person
:Vehicle�:Bike
OWNS
Label
Neo4j, Inc. CC BY-SA 4.0
Property graph database
31
Node (Vertex)
Relationship (Edge)
:Person
OWNS
Label
Properties
name: Jane
make: Specialized
model: Crux Pro
since: 2018
:Vehicle�:Bike
Neo4j, Inc. CC BY-SA 4.0
Retail Dataset - Northwind
Steps
Neo4j, Inc. CC BY-SA 4.0
Steps
Neo4j, Inc. CC BY-SA 4.0
Draw a graph model
Model
Neo4j, Inc. CC BY-SA 4.0
Map source data to your graph
Map
Neo4j, Inc. CC BY-SA 4.0
Map source data to your graph
Map
Neo4j, Inc. CC BY-SA 4.0
Draw Graph Model
Neo4j, Inc. CC BY-SA 4.0
Preview and Import your data
Import
Neo4j, Inc. CC BY-SA 4.0
Import Add Files + Map
Neo4j, Inc. CC BY-SA 4.0
Import Map
Neo4j, Inc. CC BY-SA 4.0
Import �Preview
Neo4j, Inc. CC BY-SA 4.0
Import Results
Neo4j, Inc. CC BY-SA 4.0
Preview and Import your data
Explore
Neo4j, Inc. CC BY-SA 4.0
Explore - Show me a Graph
Neo4j, Inc. CC BY-SA 4.0
Explore Path
Neo4j, Inc. CC BY-SA 4.0
Explore Path
Neo4j, Inc. CC BY-SA 4.0
Write Queries
Query
Neo4j, Inc. CC BY-SA 4.0
And now query the graph together!
Neo4j, Inc. CC BY-SA 4.0
Cypher
A pattern-matching query language made for graphs
49
Neo4j, Inc. CC BY-SA 4.0
Cypher
A pattern matching query language made for graphs�
50
Neo4j, Inc. CC BY-SA 4.0
Cypher
A pattern matching query language made for graphs�
With ASCII ART ¯\_(ツ)_/¯
51
Neo4j, Inc. CC BY-SA 4.0
dev.neo4j.com/refcard
Neo4j, Inc. CC BY-SA 4.0
Use MATCH to retrieve nodes
//Match all nodes with a Product label
MATCH (n:Product)
RETURN n;
Neo4j, Inc. CC BY-SA 4.0
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
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
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
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
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
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
MERGE
//Create a product node called "Cheese"
MERGE (p:Product {productName:"Cheese"});
Neo4j, Inc. CC BY-SA 4.0
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
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
Query - Sidebar
Neo4j, Inc. CC BY-SA 4.0
Query - Pattern
Neo4j, Inc. CC BY-SA 4.0
Query - Table
Neo4j, Inc. CC BY-SA 4.0
Build a GraphQL API
Build
Neo4j, Inc. CC BY-SA 4.0
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
GraphQL Toolbox - Type Definition
Neo4j, Inc. CC BY-SA 4.0
GraphQL Toolbox - Query
Neo4j, Inc. CC BY-SA 4.0
What Else is There?
Neo4j, Inc. CC BY-SA 4.0
Connectors
What else is there?
Drivers
Data Science
Libraries / Integrations
Neo4j, Inc. CC BY-SA 4.0
So how do I continue my graph journey?
Neo4j, Inc. CC BY-SA 4.0
Continue your journey
Free online training and certification:
How to, best practices, hands on and community stories:
Come say hello :)
Neo4j, Inc. CC BY-SA 4.0
Neo4j, Inc. CC BY-SA 4.0
Stackoverflow Demo
:play auradb/stackoverflow
Neo4j, Inc. CC BY-SA 4.0