![Page 1: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/1.jpg)
Mastering Neo4jA Graph Database
Data Masters
![Page 2: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/2.jpg)
Special Thanks To…
Planet Linux Caffehttp://planetlinuxcaffe.com
![Page 3: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/3.jpg)
We now have a sponsor!!
John Jadvani954-527-0090
![Page 4: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/4.jpg)
Short bio about me… Andrew Simkovsky 15 years working with database technology
Oracle, MySQL/MariaDB, SQL Server, Postgres
Redis, MongoDB, CouchDB, Cassandra, Neo4j Worked across many industries
Consulting, Retail, Telecommunications, Energy
Data, Marketing, Gaming, Health care
![Page 6: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/6.jpg)
Graph Databases
![Page 7: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/7.jpg)
Graph Databases
What is a graph database? Based on graph theory Data is stored as “nodes”, and
relationships as “edges” Nodes have attributes. Relationships have attributes
![Page 8: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/8.jpg)
Relational vs Graph
Relational Relationships are used to join entities together to get
results Data integrity is enforced through constraints
Graph Relationships are considered data Can easily “walk” from node to node using
relationships Can “walk” the graph in multiple directions in
parallel
![Page 9: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/9.jpg)
Relational Model
actor movieactor_movie
1, Keanu Reeves2, Carrie-Ann Moss3, Lawrence Fishburne
actor_idname
movie_idtitlerelease_date
actor_idmovie_idrole
1, The Matrix2, The Matrix Reloaded3, The Matrix Revolutions
1, 1, Neo1, 2, Neo1, 3, Neo2, 1, Trinity2, 2, Trinity2, 3, Trinity3, 1, Morpheus3, 2, Morpheus3, 3, Morpheus
![Page 10: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/10.jpg)
Graph Model
The Matrix
The Matrix 2
The Matrix 3
Keanu Reeves
Carrie-Ann Moss
Lawrence
Fishburne
![Page 11: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/11.jpg)
Graph Model - Detailed
type: Actorname: “Keanu Reeves”
type: Movietitle:
“Matrix” :ACTS_IN
type: Role, role: “Neo”
NodeRelationship
Property Value
Property
Path
![Page 12: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/12.jpg)
Example Graphs
![Page 13: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/13.jpg)
Example Graphs
![Page 14: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/14.jpg)
Example Graphs
![Page 15: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/15.jpg)
Graph Databases – Examples Uses
Social relationships
Actor / movie relationships
Medicine interactions
Just some of the many possibilities!
![Page 16: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/16.jpg)
CypherA Graph Query Language
![Page 17: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/17.jpg)
Queries
START[MATCH][WITH][WHERE]RETURN
[ORDER BY] [SKIP] [LIMIT]
Starting node(s)
Matching pattern (except properties)
Filter on properties
Properties to return
Further conditions / calculations
![Page 18: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/18.jpg)
Query Example
START user=node:nodeIndexName(name={“Bob”})MATCH (user)-[:FRIEND]->(friend)WITH user, count(friend) as friendsWHERE friends > 10RETURN friend.nameORDER BY friend.nameLIMIT 100
![Page 19: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/19.jpg)
Query Parts
START user=node:nodeIndexName(name={“Bob”})made-
up identifi
er
object type
node property identifier
index name
property
value
![Page 20: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/20.jpg)
Query Parts
MATCH (user)-[:FRIEND]->(friend)
node node
relationship definition(including direction)
Another made-up identifier
![Page 21: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/21.jpg)
Query Parts
WITH user, count(friend) as friends
grouping node
calculation
alias
![Page 22: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/22.jpg)
Query Parts
WHERE friends > 10
property filter
![Page 23: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/23.jpg)
Query Parts
RETURN friend.nameORDER BY friend.nameLIMIT 100
![Page 24: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/24.jpg)
Query Example – All Together
START user=node:nodeIndexName(name={“Bob”})MATCH (user)-[:FRIEND]->(friend)WITH user, count(friend) as friendsWHERE friends > 10RETURN friend.nameORDER BY friend.nameLIMIT 100
This will return all nodes where they are friends with Bob, and that Bob has more than 10 friends, but limit to the first 100 found.
![Page 25: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/25.jpg)
Query Example – Matching
START user=node:nodeIndexName(name={“Bob”})MATCH (user)-[:FRIEND {since: “2001-01-01”} ]->(friend)RETURN friend.name
Since relationships have properties, we can search on them too!!
![Page 26: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/26.jpg)
Creating Data
CREATE [UNIQUE]*[SET | DELETE | FOREACH]*[RETURN [ORDER BY][SKIP][LIMIT]]
![Page 27: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/27.jpg)
Creating Data - Examples
CREATE (n {name: “Bob”})
made-up identifier
again
property
value
![Page 28: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/28.jpg)
Creating Data - Examples
CREATE (b {name: “Bob”}), (m {name: “Mary”}), (b)-[:KNOWS]->(m)
Creates two nodes with a relationship between them.This is called creating a path.
![Page 29: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/29.jpg)
Creating Data - Examples
You can combine queries with create options! This allows you to create parts of the graph starting from a particular node (or nodes)!
START b=node:nodeIndexName(name={“Bob”}), m=node:nodeIndexName(name={“Mary”})MATCH (b)-[:KNOWS]->(m)CREATE (b)-[:LOVES]->(m)
![Page 30: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/30.jpg)
Live Demo!
![Page 31: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/31.jpg)
Where Do I Get It?
www.neo4j.org
![Page 32: Mastering Neo4j A Graph Database Data Masters. Special Thanks To… Planet Linux Caffe](https://reader030.vdocuments.us/reader030/viewer/2022032605/56649e835503460f94b84be7/html5/thumbnails/32.jpg)
Thank You For Coming!
Please rate this Meet Up:www.meetup.com/data-masters
(or go there to join!)
Check out my blog and forums:www.dbtekpro.com
After Party!!Miller’s Ale House
Miracle Mile