SlideShare a Scribd company logo
1 of 44
Download to read offline
Understanding Graph Databases with Neo4j 
and Cypher 
Group Members 
S.S. Niranga MS-14901836 
Nipuna Pannala MS-14902208 
Ruhaim Izmeth MS-14901218
Trends in Data 
Data is getting bigger: 
“Every 2 days we 
create as much 
information as we did 
up to 2003” 
– Eric Schmidt, Google
The History of Graph Theory 
● 1736: Leonard Euler writes a paper on the “Seven Bridges of Konisberg” 
● 1845: Gustav Kirchoff publishes his electrical circuit laws 
● 1852: Francis Guthrie poses the “Four Color Problem” 
● 1878: Sylvester publishes an article in Nature magazine that describes graphs 
● 1936: Dénes Kőnig publishes a textbook on Graph Theory 
● 1941: Ramsey and Turán define Extremal Graph Theory 
● 1959: De Bruijn publishes a paper summarizing Enumerative Graph Theory 
● 1959: Erdos, Renyi and Gilbert define Random Graph Theory 
● 1969: Heinrich Heesch solves the “Four Color” problem 
● 2003: Commercial Graph Database products start appearing on the market
What is Graph database? 
“A traditional relational database may tell you 
the average age of everyone in this room.. 
..but a graph database will tell you who 
is most likely to buy you a beer!”
What does a Graph database look like?
What is a Graph Database? 
● A database with an explicit graph structure 
● Each node knows its adjacent nodes 
● As the number of nodes increases, the cost of a local 
step (or hop) remains the same 
● Plus an Index for lookups
Compared to Relational Databases 
Optimized for aggregation Optimized for connections
Complexity Vs Size
What to Choose? 
http://db-engines.com/en/ranking/graph+dbms
What is Neo4j? 
● Neo4j is an open-source graph database, implemented in Java. 
● Neo4j version 1.0 was released in February, 2010. 
● Neo4j version 2.0 was released in December, 2013 
● Neo4j was developed by Neo Technology, Inc. 
● Neo Technology board of directors consists of Rod Johnson, 
(founder of the Spring Framework), Magnus Christerson (Vice 
President of Intentional Software Corp), Nikolaj Nyholm (CEO 
of Polar Rose), Sami Ahvenniemi (Partner at Conor Venture 
Partners) and Johan Svensson (CTO of Neo Technology).
Entities in Graph DBs (Neo4j) 
● Nodes 
● Relationships 
● Properties 
● Labels 
● Paths 
● Traversal 
● Schema (index and constraints)
Neo4j Properties 
Ex.
Ex. 
Neo4j Labels
Ex. 
Neo4j Nodes
Neo4j Relationships 
Ex.
Neo4j Paths 
Ex.
Introducing - Cypher 
Query Language for Neo4j
Relational Schema 
Person 
p_id p_name 
Book 
b_id b_title 
p_type 
Wrote 
p_id b_id 
Purchased 
p_id b_id pur_date
Cypher - Few Keywords 
General Clauses 
● Return 
● Order by 
● Limit 
Writing Clauses 
● Create 
● Merge 
● Set 
● Delete 
● Remove 
Reading Clauses 
● Match 
● Optional Match 
● Where 
● Aggregation 
Functions 
● Predicates 
● Scalar functions 
● Collection functions 
● Mathematical functions 
● String functions 
See Full list at Cypher RefCard 
http://neo4j.com/docs/stable/cypher-refcard/
Cypher Demo 
http://console.neo4j.org/ 
or 
if Neo4j is locally installed 
http://localhost:7474
Cypher 
Creating nodes 
CREATE (:Person) 
CREATE (:Person { name:"John Le 
Carre" }) 
CREATE ({ name:"John Le Carre" }) 
CREATE (:Person:Author { name:"John 
Le Carre" }) 
CREATE 
(:Person:Author { name:"Graham 
Greene" }), 
(:Book { title:"Tinker, Tailor, 
Soldier, Spy" }), 
(:Book { title:"Our Man in Havana" 
}), 
(:Person { name:"Ian" }), 
(:Person { name:"Alan" })
Cypher 
Modifying nodes 
MATCH (p:Person { namme:"Alan" }) 
SET p += {name2 : "Alan2"} 
MATCH (p:Person { namme:"Alan" }) 
SET p.name = "Alan" 
MATCH (p:Person { namme:"Alan" }) 
SET p = {name : "Alan"} 
CREATE (:Person { namme:"Alan" }) 
MATCH (p:Person { name2:"Alan2" }) 
DELETE p 
MATCH (p:Person { namme:"Alan" }) 
REMOVE p.namme
Cypher Relationships
Cypher - Creating 
Relationships 
CREATE 
(john:Person:Author { name:"John Le Carre" }), 
(b:Book { title:"Tinker, Tailor, Soldier, Spy" }), 
(john)-[:WROTE]->(b) 
MATCH 
(p:Person { name:"Ian" }), 
(b:Book { title:"Our Man in Havana" }) 
MERGE 
(p)-[:PURCHASED { date:"09-09-2011" }]->(b) 
MATCH 
(graham:Person:Author { name:" 
Graham Greene" }), 
(b:Book { title:"Our Man in 
Havana" }) 
MERGE (graham)-[:WROTE]-> 
(b) 
MATCH (t:Book { title:"Tinker, Tailor, Soldier, Spy" }), 
(i:Person { name:"Ian" }), 
(a:Person { name:"Alan" }) 
MERGE 
(i)-[:PURCHASED { date:"03-02-2011" }]->(t)<-[:PURCHASED { date:"05-07-2011" }]-(a)
Cypher - Modifying Relationships 
MATCH 
(graham:Person:Author { name:"Graham Greene" }), 
(b:Book { title:"Our Man in Havana" }) 
MERGE (graham)-[:WORTE]->(b) 
MATCH 
(graham:Person {name:"Graham Greene"})-[r]->(b:Book {title:"Our Man in Havana" }) 
DELETE r 
MATCH (p:Person { name:"Ian" })-[r]->(b:Book { title:"Our Man in Havana" }) 
SET r.date = "09-09-2012"
Cypher - Querying DBs 
Find All Books 
SQL 
SELECT * FROM Books 
Cypher Query 
MATCH (b:Book) 
RETURN b 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
Cypher Result 
+-----------------------------------------------+ 
| b | 
+-----------------------------------------------+ 
| Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | 
| Node[3]{title:"Our Man in Havana"} | 
+-----------------------------------------------+ 
2 rows 
2 ms
Cypher - Querying DBs 
Find All Authors 
SQL 
SELECT * FROM Person where p_type=” 
Author” 
Cypher Query 
MATCH (a:Author) 
RETURN a 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
Cypher Result 
+-------------------------------+ 
| a | 
+-------------------------------+ 
| Node[0]{name:"John Le Carre"} | 
| Node[1]{name:"Graham Greene"} | 
+-------------------------------+ 
2 rows 
8 ms
Cypher - Querying DBs 
Find All Authors and the Books written by them 
SQL 
SELECT p.p_name, b.b_title 
FROM Person p, Wrote w, 
Book b 
where p.p_type=”Author” and 
w.p_id = p.p_id and 
w.b_id = b.b_id 
Cypher Query 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
MATCH (a:Author)-[:WROTE]->(b: 
Book) 
RETURN a,b 
Cypher Result 
+-------------------------------------------------------------------------------+ 
| a | b | 
+-------------------------------------------------------------------------------+ 
| Node[0]{name:"John Le Carre"} | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | 
| Node[1]{name:"Graham Greene"} | Node[3]{title:"Our Man in Havana"} | 
+-------------------------------------------------------------------------------+ 
2 rows 
12 ms
Cypher - Querying DBs 
Find Books written by Graham Greene 
SQL 
SELECT b.b_title 
FROM Person p, Wrote w, 
Book b 
where p.p_type=”Author” and 
w.p_id = p.p_id and 
w.b_id = b.b_id and 
p.name = “Graham Greene” 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
Cypher Query 
MATCH (a:Author)-[:WROTE]->(b: 
Book) 
WHERE a.name = 'Graham Greene' 
RETURN b 
Cypher Result 
+------------------------------------+ 
| b | 
+------------------------------------+ 
| Node[3]{title:"Our Man in Havana"} | 
+------------------------------------+ 
1 row 
13 ms
Cypher - Querying DBs 
Find names of all persons, the books they purchased 
and the date the purchase was made 
SQL 
SELECT p.p_name, pur.pur_date, 
b.b_title 
FROM Person p, Book b, 
Purchased pur 
WHERE pur.p_id=p.p_id and b. 
b_id = pur.b_id 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
Cypher Query 
MATCH 
(a)-[r:PURCHASED]->(b) 
RETURN a,r.date,b 
Cypher Result 
+-------------------------------------------------------------------------------------+ 
| a | r.date | b | 
+-------------------------------------------------------------------------------------+ 
| Node[4]{name:"Ian"} | "09-09-2011" | Node[3]{title:"Our Man in Havana"} | 
| Node[4]{name:"Ian"} | "03-02-2011" | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | 
| Node[5]{name:"Alan"} | "05-07-2011" | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | 
+-------------------------------------------------------------------------------------+ 
3 rows
Cypher - Querying DBs 
Find how Graham Greene is related to Ian 
SQL 
I won’t attempt!!! 
Person (p_id, p_name, p_type) 
Wrote (p_id, b_id) 
Book (b_id, b_title ) 
Purchased (p_id, b_id, 
pur_date) 
Cypher Query 
MATCH 
(a:Author)-[r*]-(p:Person { name:'Ian' }) 
WHERE a.name = 'Graham Greene' 
RETURN a,r,p 
Cypher Result 
+--------------------------------------------------------------------------------------------------------+ 
| a | r | p | 
+--------------------------------------------------------------------------------------------------------+ 
| Node[1]{name:"Graham Greene"} | [:WROTE[1] {},:PURCHASED[0] {date:"09-09-2011"}] | Node[4]{name:"Ian"} | 
+--------------------------------------------------------------------------------------------------------+ 
1 row 
38 ms
Support for Graph Algorithms 
● shortestPath 
● allSimplePaths 
● allPaths 
● dijkstra (optionally with 
cost_property and 
default_cost 
parameters)
Neo4j - Default locking behavior for 
Concurrency 
● When adding, changing or removing a property on a 
node or relationship a write lock will be taken on the 
specific node or relationship. 
● When creating or deleting a node a write lock will be 
taken for the specific node. 
● When creating or deleting a relationship a write lock will 
be taken on the specific relationship and both its nodes.
Neo4j - Performance 
● As JVM runs on a shared environment, the way the 
JVM is configured greatly related to Performance. 
● More optimized for querying than CRUD operations, 
Batch updates are recommended 
● Indexes can be set on nodes, relationships and their 
properties. Can boost query response times 
● Mixed reports on querytimes and performance, 
upcoming releases are optimizing this.
Neo4j Capacity - Data size 
In Neo4j, data size is mainly limited by the address space 
of the primary keys for Nodes, Relationships, Properties 
and Relationship types. Currently, the address space is as 
follows: 
nodes 2^35 (∼ 34 billion) 
relationships 2^35 (∼ 34 billion) 
properties 2^36 to 2^38 depending on property types (maximum ∼ 
274 billion, always at least ∼ 68 billion) 
relationship 
types 
2^15 (∼ 32 000)
Calling Neo4j 
JVM Server 
Neo4j DB 
Java Application 
Web Application Web REST API 
Java API 
Officially supported languages 
● Java 
● .NET 
● JavaScript 
● Python 
● Ruby 
● PHP
Neo4j Editions 
Enterprise 
Enterprise Lock Manager 
High Performance Cache 
Clustering 
Hot Backups 
Advanced Monitoring 
NOT FREE 
Community 
FREE 
OPEN SOURCE
If you’ve ever 
● Joined more than 7 tables together 
● Modeled a graph in a table 
● Written a recursive CTE (Common Table Expression) 
● Tried to write some crazy stored procedure with multiple 
recursive self and inner joins 
You should use Neo4j
Disadvantages 
● JVM should configured properly to get the 
optimal performance. 
● Neo4j DB cannot be distributed. They should 
replicated. 
● Inappropriate for transactional information 
like accounting and banking.
Who use Neo4j?
Thank you !!!

More Related Content

What's hot

Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Jonathan Katz
 
Hash - A probabilistic approach for big data
Hash - A probabilistic approach for big dataHash - A probabilistic approach for big data
Hash - A probabilistic approach for big dataLuca Mastrostefano
 
Cloud flare jgc bigo meetup rolling hashes
Cloud flare jgc   bigo meetup rolling hashesCloud flare jgc   bigo meetup rolling hashes
Cloud flare jgc bigo meetup rolling hashesCloudflare
 
Schema Design by Chad Tindel, Solution Architect, 10gen
Schema Design  by Chad Tindel, Solution Architect, 10genSchema Design  by Chad Tindel, Solution Architect, 10gen
Schema Design by Chad Tindel, Solution Architect, 10genMongoDB
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesIbrar Ahmed
 
The Weather of the Century Part 3: Visualization
The Weather of the Century Part 3: VisualizationThe Weather of the Century Part 3: Visualization
The Weather of the Century Part 3: VisualizationMongoDB
 
The Weather of the Century
The Weather of the CenturyThe Weather of the Century
The Weather of the CenturyMongoDB
 
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...Amazon Web Services
 
PyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and MapsPyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and MapsHannes Hapke
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeKonrad Malawski
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012yantoit2011
 
Weather of the Century: Visualization
Weather of the Century: VisualizationWeather of the Century: Visualization
Weather of the Century: VisualizationMongoDB
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)Mike Dirolf
 
Java Performance Tips (So Code Camp San Diego 2014)
Java Performance Tips (So Code Camp San Diego 2014)Java Performance Tips (So Code Camp San Diego 2014)
Java Performance Tips (So Code Camp San Diego 2014)Kai Chan
 
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)Kai Chan
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWAnkur Raina
 
Unified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco SystemsUnified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco SystemsAltinity Ltd
 
Data science at the command line
Data science at the command lineData science at the command line
Data science at the command lineSharat Chikkerur
 

What's hot (20)

Hadoop london
Hadoop londonHadoop london
Hadoop london
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
 
Hash - A probabilistic approach for big data
Hash - A probabilistic approach for big dataHash - A probabilistic approach for big data
Hash - A probabilistic approach for big data
 
Cloud flare jgc bigo meetup rolling hashes
Cloud flare jgc   bigo meetup rolling hashesCloud flare jgc   bigo meetup rolling hashes
Cloud flare jgc bigo meetup rolling hashes
 
Schema Design by Chad Tindel, Solution Architect, 10gen
Schema Design  by Chad Tindel, Solution Architect, 10genSchema Design  by Chad Tindel, Solution Architect, 10gen
Schema Design by Chad Tindel, Solution Architect, 10gen
 
Deep dive to PostgreSQL Indexes
Deep dive to PostgreSQL IndexesDeep dive to PostgreSQL Indexes
Deep dive to PostgreSQL Indexes
 
The Weather of the Century Part 3: Visualization
The Weather of the Century Part 3: VisualizationThe Weather of the Century Part 3: Visualization
The Weather of the Century Part 3: Visualization
 
The Weather of the Century
The Weather of the CenturyThe Weather of the Century
The Weather of the Century
 
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...
(SDD407) Amazon DynamoDB: Data Modeling and Scaling Best Practices | AWS re:I...
 
PyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and MapsPyDX Presentation about Python, GeoData and Maps
PyDX Presentation about Python, GeoData and Maps
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of code
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012
 
Weather of the Century: Visualization
Weather of the Century: VisualizationWeather of the Century: Visualization
Weather of the Century: Visualization
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
Mongo Baseball .NET
Mongo Baseball .NETMongo Baseball .NET
Mongo Baseball .NET
 
Java Performance Tips (So Code Camp San Diego 2014)
Java Performance Tips (So Code Camp San Diego 2014)Java Performance Tips (So Code Camp San Diego 2014)
Java Performance Tips (So Code Camp San Diego 2014)
 
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
Search Engine-Building with Lucene and Solr, Part 1 (SoCal Code Camp LA 2013)
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
 
Unified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco SystemsUnified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco Systems
 
Data science at the command line
Data science at the command lineData science at the command line
Data science at the command line
 

Viewers also liked

Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...Neo4j
 
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 EditionIntroduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 EditionAleksander Stensby
 
Cypher Query Language
Cypher Query Language Cypher Query Language
Cypher Query Language graphdevroom
 
Intro to Cypher
Intro to CypherIntro to Cypher
Intro to Cypherjexp
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .NetNeo4j
 
Neo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> CypherNeo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> Cypherjexp
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) David Fombella Pombal
 

Viewers also liked (8)

Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
Avoiding Deadlocks: Lessons Learned with Zephyr Health Using Neo4j and MongoD...
 
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 EditionIntroduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
 
Cypher Query Language
Cypher Query Language Cypher Query Language
Cypher Query Language
 
Intro to Cypher
Intro to CypherIntro to Cypher
Intro to Cypher
 
Cypher
CypherCypher
Cypher
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
 
Neo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> CypherNeo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> Cypher
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
 

Similar to Understanding Graph Databases with Neo4j and Cypher

The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelineMongoDB
 
Cypher and apache spark multiple graphs and more in open cypher
Cypher and apache spark  multiple graphs and more in  open cypherCypher and apache spark  multiple graphs and more in  open cypher
Cypher and apache spark multiple graphs and more in open cypherNeo4j
 
Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Chakrit Phain
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPJeremy Kendall
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...MongoDB
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"MongoDB
 
New opportunities for connected data
New opportunities for connected dataNew opportunities for connected data
New opportunities for connected dataNeo4j
 
Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)Patrick Baumgartner
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
A Survey Of R Graphics
A Survey Of R GraphicsA Survey Of R Graphics
A Survey Of R GraphicsDataspora
 
Webinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasWebinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasMongoDB
 
Mapping Graph Queries to PostgreSQL
Mapping Graph Queries to PostgreSQLMapping Graph Queries to PostgreSQL
Mapping Graph Queries to PostgreSQLGábor Szárnyas
 
Introduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4JIntroduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4JBrant Boehmann
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jSerendio Inc.
 
Strongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasStrongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasNorberto Leite
 

Similar to Understanding Graph Databases with Neo4j and Cypher (20)

The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
Powerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation PipelinePowerful Analysis with the Aggregation Pipeline
Powerful Analysis with the Aggregation Pipeline
 
Cypher and apache spark multiple graphs and more in open cypher
Cypher and apache spark  multiple graphs and more in  open cypherCypher and apache spark  multiple graphs and more in  open cypher
Cypher and apache spark multiple graphs and more in open cypher
 
Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้Neo4j Graph Database และการประยุกตร์ใช้
Neo4j Graph Database และการประยุกตร์ใช้
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
 
Rug hogan-10-03-2012
Rug hogan-10-03-2012Rug hogan-10-03-2012
Rug hogan-10-03-2012
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
 
New opportunities for connected data
New opportunities for connected dataNew opportunities for connected data
New opportunities for connected data
 
Geospatial Data in R
Geospatial Data in RGeospatial Data in R
Geospatial Data in R
 
Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
A Survey Of R Graphics
A Survey Of R GraphicsA Survey Of R Graphics
A Survey Of R Graphics
 
Webinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasWebinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible Schemas
 
Mapping Graph Queries to PostgreSQL
Mapping Graph Queries to PostgreSQLMapping Graph Queries to PostgreSQL
Mapping Graph Queries to PostgreSQL
 
Introduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4JIntroduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4J
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4j
 
Strongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasStrongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible Schemas
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

Understanding Graph Databases with Neo4j and Cypher

  • 1. Understanding Graph Databases with Neo4j and Cypher Group Members S.S. Niranga MS-14901836 Nipuna Pannala MS-14902208 Ruhaim Izmeth MS-14901218
  • 2. Trends in Data Data is getting bigger: “Every 2 days we create as much information as we did up to 2003” – Eric Schmidt, Google
  • 3. The History of Graph Theory ● 1736: Leonard Euler writes a paper on the “Seven Bridges of Konisberg” ● 1845: Gustav Kirchoff publishes his electrical circuit laws ● 1852: Francis Guthrie poses the “Four Color Problem” ● 1878: Sylvester publishes an article in Nature magazine that describes graphs ● 1936: Dénes Kőnig publishes a textbook on Graph Theory ● 1941: Ramsey and Turán define Extremal Graph Theory ● 1959: De Bruijn publishes a paper summarizing Enumerative Graph Theory ● 1959: Erdos, Renyi and Gilbert define Random Graph Theory ● 1969: Heinrich Heesch solves the “Four Color” problem ● 2003: Commercial Graph Database products start appearing on the market
  • 4. What is Graph database? “A traditional relational database may tell you the average age of everyone in this room.. ..but a graph database will tell you who is most likely to buy you a beer!”
  • 5.
  • 6. What does a Graph database look like?
  • 7. What is a Graph Database? ● A database with an explicit graph structure ● Each node knows its adjacent nodes ● As the number of nodes increases, the cost of a local step (or hop) remains the same ● Plus an Index for lookups
  • 8. Compared to Relational Databases Optimized for aggregation Optimized for connections
  • 10. What to Choose? http://db-engines.com/en/ranking/graph+dbms
  • 11. What is Neo4j? ● Neo4j is an open-source graph database, implemented in Java. ● Neo4j version 1.0 was released in February, 2010. ● Neo4j version 2.0 was released in December, 2013 ● Neo4j was developed by Neo Technology, Inc. ● Neo Technology board of directors consists of Rod Johnson, (founder of the Spring Framework), Magnus Christerson (Vice President of Intentional Software Corp), Nikolaj Nyholm (CEO of Polar Rose), Sami Ahvenniemi (Partner at Conor Venture Partners) and Johan Svensson (CTO of Neo Technology).
  • 12. Entities in Graph DBs (Neo4j) ● Nodes ● Relationships ● Properties ● Labels ● Paths ● Traversal ● Schema (index and constraints)
  • 18.
  • 19. Introducing - Cypher Query Language for Neo4j
  • 20.
  • 21. Relational Schema Person p_id p_name Book b_id b_title p_type Wrote p_id b_id Purchased p_id b_id pur_date
  • 22. Cypher - Few Keywords General Clauses ● Return ● Order by ● Limit Writing Clauses ● Create ● Merge ● Set ● Delete ● Remove Reading Clauses ● Match ● Optional Match ● Where ● Aggregation Functions ● Predicates ● Scalar functions ● Collection functions ● Mathematical functions ● String functions See Full list at Cypher RefCard http://neo4j.com/docs/stable/cypher-refcard/
  • 23. Cypher Demo http://console.neo4j.org/ or if Neo4j is locally installed http://localhost:7474
  • 24. Cypher Creating nodes CREATE (:Person) CREATE (:Person { name:"John Le Carre" }) CREATE ({ name:"John Le Carre" }) CREATE (:Person:Author { name:"John Le Carre" }) CREATE (:Person:Author { name:"Graham Greene" }), (:Book { title:"Tinker, Tailor, Soldier, Spy" }), (:Book { title:"Our Man in Havana" }), (:Person { name:"Ian" }), (:Person { name:"Alan" })
  • 25. Cypher Modifying nodes MATCH (p:Person { namme:"Alan" }) SET p += {name2 : "Alan2"} MATCH (p:Person { namme:"Alan" }) SET p.name = "Alan" MATCH (p:Person { namme:"Alan" }) SET p = {name : "Alan"} CREATE (:Person { namme:"Alan" }) MATCH (p:Person { name2:"Alan2" }) DELETE p MATCH (p:Person { namme:"Alan" }) REMOVE p.namme
  • 27. Cypher - Creating Relationships CREATE (john:Person:Author { name:"John Le Carre" }), (b:Book { title:"Tinker, Tailor, Soldier, Spy" }), (john)-[:WROTE]->(b) MATCH (p:Person { name:"Ian" }), (b:Book { title:"Our Man in Havana" }) MERGE (p)-[:PURCHASED { date:"09-09-2011" }]->(b) MATCH (graham:Person:Author { name:" Graham Greene" }), (b:Book { title:"Our Man in Havana" }) MERGE (graham)-[:WROTE]-> (b) MATCH (t:Book { title:"Tinker, Tailor, Soldier, Spy" }), (i:Person { name:"Ian" }), (a:Person { name:"Alan" }) MERGE (i)-[:PURCHASED { date:"03-02-2011" }]->(t)<-[:PURCHASED { date:"05-07-2011" }]-(a)
  • 28. Cypher - Modifying Relationships MATCH (graham:Person:Author { name:"Graham Greene" }), (b:Book { title:"Our Man in Havana" }) MERGE (graham)-[:WORTE]->(b) MATCH (graham:Person {name:"Graham Greene"})-[r]->(b:Book {title:"Our Man in Havana" }) DELETE r MATCH (p:Person { name:"Ian" })-[r]->(b:Book { title:"Our Man in Havana" }) SET r.date = "09-09-2012"
  • 29. Cypher - Querying DBs Find All Books SQL SELECT * FROM Books Cypher Query MATCH (b:Book) RETURN b Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) Cypher Result +-----------------------------------------------+ | b | +-----------------------------------------------+ | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | | Node[3]{title:"Our Man in Havana"} | +-----------------------------------------------+ 2 rows 2 ms
  • 30. Cypher - Querying DBs Find All Authors SQL SELECT * FROM Person where p_type=” Author” Cypher Query MATCH (a:Author) RETURN a Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) Cypher Result +-------------------------------+ | a | +-------------------------------+ | Node[0]{name:"John Le Carre"} | | Node[1]{name:"Graham Greene"} | +-------------------------------+ 2 rows 8 ms
  • 31. Cypher - Querying DBs Find All Authors and the Books written by them SQL SELECT p.p_name, b.b_title FROM Person p, Wrote w, Book b where p.p_type=”Author” and w.p_id = p.p_id and w.b_id = b.b_id Cypher Query Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) MATCH (a:Author)-[:WROTE]->(b: Book) RETURN a,b Cypher Result +-------------------------------------------------------------------------------+ | a | b | +-------------------------------------------------------------------------------+ | Node[0]{name:"John Le Carre"} | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | | Node[1]{name:"Graham Greene"} | Node[3]{title:"Our Man in Havana"} | +-------------------------------------------------------------------------------+ 2 rows 12 ms
  • 32. Cypher - Querying DBs Find Books written by Graham Greene SQL SELECT b.b_title FROM Person p, Wrote w, Book b where p.p_type=”Author” and w.p_id = p.p_id and w.b_id = b.b_id and p.name = “Graham Greene” Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) Cypher Query MATCH (a:Author)-[:WROTE]->(b: Book) WHERE a.name = 'Graham Greene' RETURN b Cypher Result +------------------------------------+ | b | +------------------------------------+ | Node[3]{title:"Our Man in Havana"} | +------------------------------------+ 1 row 13 ms
  • 33. Cypher - Querying DBs Find names of all persons, the books they purchased and the date the purchase was made SQL SELECT p.p_name, pur.pur_date, b.b_title FROM Person p, Book b, Purchased pur WHERE pur.p_id=p.p_id and b. b_id = pur.b_id Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) Cypher Query MATCH (a)-[r:PURCHASED]->(b) RETURN a,r.date,b Cypher Result +-------------------------------------------------------------------------------------+ | a | r.date | b | +-------------------------------------------------------------------------------------+ | Node[4]{name:"Ian"} | "09-09-2011" | Node[3]{title:"Our Man in Havana"} | | Node[4]{name:"Ian"} | "03-02-2011" | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | | Node[5]{name:"Alan"} | "05-07-2011" | Node[2]{title:"Tinker, Tailor, Soldier, Spy"} | +-------------------------------------------------------------------------------------+ 3 rows
  • 34. Cypher - Querying DBs Find how Graham Greene is related to Ian SQL I won’t attempt!!! Person (p_id, p_name, p_type) Wrote (p_id, b_id) Book (b_id, b_title ) Purchased (p_id, b_id, pur_date) Cypher Query MATCH (a:Author)-[r*]-(p:Person { name:'Ian' }) WHERE a.name = 'Graham Greene' RETURN a,r,p Cypher Result +--------------------------------------------------------------------------------------------------------+ | a | r | p | +--------------------------------------------------------------------------------------------------------+ | Node[1]{name:"Graham Greene"} | [:WROTE[1] {},:PURCHASED[0] {date:"09-09-2011"}] | Node[4]{name:"Ian"} | +--------------------------------------------------------------------------------------------------------+ 1 row 38 ms
  • 35. Support for Graph Algorithms ● shortestPath ● allSimplePaths ● allPaths ● dijkstra (optionally with cost_property and default_cost parameters)
  • 36. Neo4j - Default locking behavior for Concurrency ● When adding, changing or removing a property on a node or relationship a write lock will be taken on the specific node or relationship. ● When creating or deleting a node a write lock will be taken for the specific node. ● When creating or deleting a relationship a write lock will be taken on the specific relationship and both its nodes.
  • 37. Neo4j - Performance ● As JVM runs on a shared environment, the way the JVM is configured greatly related to Performance. ● More optimized for querying than CRUD operations, Batch updates are recommended ● Indexes can be set on nodes, relationships and their properties. Can boost query response times ● Mixed reports on querytimes and performance, upcoming releases are optimizing this.
  • 38. Neo4j Capacity - Data size In Neo4j, data size is mainly limited by the address space of the primary keys for Nodes, Relationships, Properties and Relationship types. Currently, the address space is as follows: nodes 2^35 (∼ 34 billion) relationships 2^35 (∼ 34 billion) properties 2^36 to 2^38 depending on property types (maximum ∼ 274 billion, always at least ∼ 68 billion) relationship types 2^15 (∼ 32 000)
  • 39. Calling Neo4j JVM Server Neo4j DB Java Application Web Application Web REST API Java API Officially supported languages ● Java ● .NET ● JavaScript ● Python ● Ruby ● PHP
  • 40. Neo4j Editions Enterprise Enterprise Lock Manager High Performance Cache Clustering Hot Backups Advanced Monitoring NOT FREE Community FREE OPEN SOURCE
  • 41. If you’ve ever ● Joined more than 7 tables together ● Modeled a graph in a table ● Written a recursive CTE (Common Table Expression) ● Tried to write some crazy stored procedure with multiple recursive self and inner joins You should use Neo4j
  • 42. Disadvantages ● JVM should configured properly to get the optimal performance. ● Neo4j DB cannot be distributed. They should replicated. ● Inappropriate for transactional information like accounting and banking.