SlideShare a Scribd company logo
The world's leading graph DB
Georgios Eleftheriadis
Software/Database Engineer
What is NOSQL?
 It’s not “No to SQL”
 It’s not “Never SQL”
 It’s “Not Only SQL” as they may support SQL-like query languages
NOSQL describes ongoing trend where developers increasingly opt for non-relational databases to
help solve their problems, in an effort to use the right tool for the right job.
 NOSQL example databases
 Document Oriented (CouchDB, MongoDB)
 Key-Value (Memcached, Redis)
 Graph Database (Neo4J, InfiniteGraph)
 Multi-model (ArangoDB, OrientDB)
2
Graphs are everywhere
 Relationships in
 Politics, Economics, History, Science, Transportation
 Biology, Chemistry, Physics, Sociology
 Body, Ecosphere, Reaction, Interactions
 Internet
 Hardware, Software, Interaction
 Social Networks
 Family, Friends
 Work, Communities
 Neighbors, Cities, Society
3
A sample social graph
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000 2ms
 with ~1,000 persons
 average 50 friends per person
 pathExists(a,b) limited to depth 4
 caches warmed up to eliminate disk I/O
4
A sample social graph
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000 2ms
 with ~1,000 persons
 average 50 friends per person
 pathExists(a,b) limited to depth 4
 caches warmed up to eliminate disk I/O
5
A sample social graph
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000 2ms
 with ~1,000 persons
 average 50 friends per person
 pathExists(a,b) limited to depth 4
 caches warmed up to eliminate disk I/O
6
Two Ways to Work with Neo4j
 Embeddable on JVM
 Java
 Jruby
 Scala
 Tomcat
 Rails
 Server with REST API
 every language on the planet
 flexible deployment scenarios
 DIY server or cloud managed
Embedded capability == Server capability
same scalability, transactionality, and availability
7
Pros & Cons with Neo4j Database
 Pros
 Most of the data is connected
 High performance to access connected data
 Least or no impact if changes to the data
model
 Can be mixed with JPA with Spring Data Neo4j
 Integrate with Spring
 Cons
 Could not reuse SQL queries
 Migration could be pain
 Not effective to use Neo4j if data is not
connected
8
Enterprise VS Community Edition
Features Enterprise Community
Property Graph Model YES YES
Native Graph Processing & Storage YES YES
Cypher – Graph Query Language YES YES
Language Drivers YES YES
REST & High-Performance Native API YES YES
Enterprise Lock Manager YES NO
Cache Sharding YES NO
Clustered Replication YES NO
Hot Backups YES NO
Advanced Monitoring YES NO 9
RDBMS vs Graph DB
10
ID Name Grade
1510 Jordan 9
1689 Gabriel 9
1381 Tiffany 9
1709 Cassandra 9
1101 Haley 10
1782 Andrew 10
1468 Kris 10
1641 Brittany 10
1247 Alexis 11
1316 Austin 11
1911 Gabriel 11
1501 Jessica 11
1304 Jordan 12
1025 John 12
1934 Kyle 12
1661 Logan 12
ID1 ID2
1510 1381
1510 1689
1689 1709
1381 1247
1709 1247
1689 1782
1782 1468
1782 1316
1782 1304
1468 1101
1468 1641
1101 1641
… …
ID1 ID2
1689 1709
1709 1689
1782 1709
1911 1247
1247 1468
1641 1468
1316 1304
1501 1934
1934 1501
1025 1101
Cypher Query Language
 Declarative query language
 Describe what you want, not how
 Based on pattern matching
11
CQL MATCH
 MATCH (a)-->(b)
RETURN a, b;
 MATCH (a)-->()
RETURN a.name;
 MATCH (n)-[r]->(m)
RETURN n, r, m;
 MATCH (a)-[r]->()
RETURN id(a), labels(a), keys(a), type(r);
 MATCH (a)-[r:ACTED_IN]->(m)
RETURN a.name, r.roles, m.title;
12
CQL MATCH
 MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
RETURN a.name, m.title, d.name;
 MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
RETURN a.name AS actor, m.title AS movie, d.name AS director;
 MATCH (a)-[:ACTED_IN]->(m)
OPTIONAL MATCH (d)-[:DIRECTED]->(m)
RETURN a.name, m.title, d.name;
 MATCH (a)-[:ACTED_IN]->(m), (d)-[:DIRECTED]->(m)
RETURN a.name, m.title, d.name;
 MATCH p=(a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)
RETURN nodes(p);
13
CQL MATCH Functions
 count(x) - add up the number of occurrences
 min(x) - get the lowest value
 max(x) - get the highest value
 avg(x) - get the average of a numeric value
 collect(x) - collected all the occurrences into an array
14
CQL WHERE
 MATCH (tom{name:"Tom Hanks"})-[:ACTED_IN]->(movie)
WHERE movie.released < 1992
RETURN DISTINCT movie.title;
 MATCH (actor{name:"Keanu Reeves"})-[r:ACTED_IN]->(movie)
WHERE "Neo" IN r.roles
RETURN DISTINCT movie.title;
 MATCH (tom{name:"Tom Hanks"})-[:ACTED_IN]->(movie)<-[:ACTED_IN]-(a)
WHERE a.born < tom.born
RETURN DISTINCT a.name, (tom.born - a.born) AS diff;
 MATCH (kevin {name:"Kevin Bacon"})-[:ACTED_IN]->(movie)
RETURN DISTINCT movie.title;
 MATCH (kevin)-[:ACTED_IN]->(movie)
WHERE kevin.name =~ '.*Kevin.*‘ // Regular expressions
RETURN DISTINCT movie.title;
15
CQL WHERE
 MATCH (gene {name:"Gene Hackman"})-[:ACTED_IN]->(movie)<-[:ACTED_IN]-(n)
WHERE (n)-[:DIRECTED]->()
RETURN DISTINCT n.name;
 MATCH (a)-[:ACTED_IN]->()
RETURN a.name, count(*) AS count
ORDER BY count DESC LIMIT 5;
 MATCH (keanu {name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(c),
(c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)
WHERE NOT((keanu)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)) AND coc <> keanu
RETURN coc.name, count(coc)
ORDER BY count(coc) DESC LIMIT 3;
// Recommend 5 actors that Keanu Reeves should work with (but hasn't)
16
CQL CREATE
 CREATE ({title:"Mystic River", released:1993});
 MATCH (movie {title:"Mystic River"})
SET movie.tagline = "We bury our sins here, Dave. We wash them clean."
RETURN movie;
 MATCH (kevin {name:"Kevin Bacon"}),(movie {title:"Mystic River"})
CREATE UNIQUE (kevin)-[:ACTED_IN {roles:["Sean"]}]->(movie);
 MATCH (kevin {name:"Kevin Bacon"})-[r:ACTED_IN]->(movie {title:"Mystic River"})
SET r.roles = ["Sean Devine"]
RETURN r.roles;
 MATCH (clint {name:"Clint Eastwood"})-[r:ACTED_IN]->(movie {title:"Mystic River"})
CREATE UNIQUE (clint)-[:DIRECTED]->(movie);
17
CQL DELETE
 MATCH (matrix {title:"The Matrix"})<-[r:ACTED_IN]-(a)
WHERE "Emil" IN r.roles
RETURN a;
// Emil Eifrem is CEO of Neo Technology and co-founder of the Neo4j project
 MATCH (emil{name:"Emil Eifrem"})
DELETE emil;
 MATCH (emil{name:"Emil Eifrem"}) -[r]-()
DELETE r;
 MATCH (emil{name:"Emil Eifrem"}) -[r]-()
DELETE r, emil;
 MATCH (node) where ID(node)=1
OPTIONAL MATCH (node)-[r]-()
DELETE r, node;
18
SQL VS Cypher
MATCH (keanu:Person { name: 'Keanu Reeves' })-[:ACTED_IN]->(movie:Movie),
(director:Person)-[:DIRECTED]->(movie)
RETURN director.name, count(*)
ORDER BY count(*) DESC
19
SELECT director.name, count(*) FROM person Keanu
JOIN acted_in ON keanu.id = acted_in.person_id
JOIN directed ON acted_in.movie_id = directed.movie_id
JOIN person AS director ON directed.person_id = director.id
WHERE keanu.name = 'Keanu Reeves‘
GROUP BY director.name ORDER BY count(*) DESC
Now let’s find out a bit about the directors in movies that Keanu Reeves acted in. We want to know
how many of those movies each of them directed.
CQL INDEXES
There is usually no need to specify which indexes to use in a query, Cypher will figure that out by itself. Indexes are also
automatically used for equality comparisons and inequality (range) comparisons of an indexed property in the WHERE
clause. USING is used to influence the decisions of the planner when building an execution plan for a query.
 CREATE INDEX ON :Person(name)
 MATCH (person:Person { name: 'Keanu Reeves' })
RETURN person
 MATCH (person:Person)
WHERE person.name = 'Keanu Reeves'
RETURN person
 MATCH (person:Person)
WHERE person.name > 'Keanu'
RETURN person
 MATCH (person:Person)
WHERE person.name STARTS WITH 'Kea' // CONTAINS, ENDS WITH
RETURN person
20
Embedded example code
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/neo-4j");
try (Transaction tx = graphDb.beginTx()) {
Node firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
Node secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
Relationship relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
tx.success();
}
21
Shortest path example code
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/neo-4j");
try (Transaction tx = graphDb.beginTx()) {
static Index<Node> indexService = graphDb.index().forNodes("nodes");
Node neo = indexService.get(“name", “Neo").getSingle();
Node agentSmith = indexService.get(“name", "Agent Smith").getSingle();
PathFinder<Path> finder = GraphAlgoFactory.shortestPath(
PathExpanders.forTypeAndDirection(KNOWS, Direction.BOTH), 4);
Path foundPath = finder.findSinglePath(neo, agentSmith);
System.out.println(Paths.simplePathToString(foundPath, NAME_KEY));
}
22
CQL Do-It-Yourself
 Add KNOWS relationships between all actors who were in the same movie
23
 MATCH (a)-[:ACTED_IN]->()<-[:ACTED_IN]-(b)
CREATE UNIQUE (a)-[:KNOWS]->(b);
 MATCH (a)-[:ACTED_IN|DIRECTED]->()<-[:ACTED_IN|DIRECTED]-(b)
CREATE UNIQUE (a)-[:KNOWS]->(b);
CQL Useful Tricks
 Find friends of friends
 MATCH (keanu{name:"Keanu Reeves"})-[:KNOWS*2]->(fof)
WHERE NOT((keanu)-[:KNOWS]-(fof))
RETURN DISTINCT fof.name;
 Find shortest path
 MATCH p=shortestPath(
(charlize{name:"Charlize Theron"})-[:KNOWS*]->(bacon{name:"Kevin Bacon"}))
RETURN length(rels(p));
 Return the names of the people joining Charlize to Kevin.
 MATCH p=shortestPath(
(charlize{name:"Charlize Theron"})-[:KNOWS*]->(bacon{name:"Kevin Bacon"}))
RETURN extract(n IN nodes(p)| n.name) AS names
24
CQL Useful Tricks
 Find movies and actors up to 4 "hops" away from Kevin Bacon
 MATCH (bacon:Person {name:"Kevin Bacon"})-[*1..4]-(hollywood)
RETURN DISTINCT Hollywood
 Find someone to introduce Tom Hanks to Tom Cruise
 MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors),
(coActors)-[:ACTED_IN]->(m2)<-[:ACTED_IN]-(cruise:Person {name:"Tom Cruise"})
RETURN tom, m, coActors, m2, cruise
25
Social Network Database
Relationship Type Properties
IS_FRIEND since
LIKES
WROTE_COMMENT
HAS_COMMENT
UPLOADED
SENT_MESSAGE
RECEIVED_MESSAGE
TAGGED_IN
Node Labels Properties
Person name, email, dob
Photo caption, date
Status text, date
Comment text, date
Message Text, date
26
Social Network Database (2)
 CREATE (ann:Person { name: 'Ann', email:'ann@neo.4j', dob:487119060000 })
RETURN ann;
 CREATE (john:Person { name: 'John', email:'john@neo.4j', dob:435679060000 })
RETURN john;
 MATCH (ann:Person { name: 'Ann' }), (john:Person { name: 'John' })
CREATE UNIQUE (ann)-[:IS_FRIEND{since:'2009'}]-(john);
 MATCH (ann:Person { name: 'Ann' })
CREATE (ann)-[:UPLOADED]->(status:Status{text:'Happy Birthday', date:1451610010000});
 MATCH (john:Person { name: 'John' }), (status:Status{text:'Happy Birthday'})
CREATE (john)-[:LIKES]->(status);
27
Social Network Database (3)
 MATCH (john:Person { name: 'John' })
CREATE (john)-[:UPLOADED]->(photo:Photo{text:'Birthday Party', date:1452410019386});
 MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'})
CREATE (ann)-[:LIKES]->(photo);
 MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'})
CREATE (ann)-[:WROTE_COMMENT]->(comment:Comment{text:'Happy Birthday. The party was
great!', date:1452410478569})<-[:HAS_COMMENT]-(photo);
 MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'})
CREATE (ann)-[:TAGGED_IN]->(photo);
28
Social Network Database (4)
 MATCH (john:Person { name: 'John' })
RETURN (john)-[:UPLOADED]->(:Photo);
 MATCH (ann:Person { name: 'Ann' }) -[:LIKES]->(photo:Photo)
RETURN ann, photo;
 MATCH (ann:Person { name: 'Ann' })-[:IS_FRIEND]-(:Person)-[:UPLOADED]-(photo:Photo)
RETURN ann, photo
 MATCH (ann:Person { name: 'Ann' })-[:IS_FRIEND]-(friend:Person),
(friend:Person)-[:UPLOADED]-(photo:Photo)
RETURN ann, photo, friend
29
How to get started?
 Documentation
 http://neo4j.com/docs/ - tutorials & reference
 Neo4j in Action
 Graph Databases by O'Reilly
 Get Neo4j
 http://neo4j.org/download
 http://elements.heroku.com/addons/graphenedb
 Participate
 http://groups.google.com/group/neo4j
 http://neo4j.meetup.com
 http://stackoverflow.com/questions/tagged/neo4j
30

More Related Content

What's hot

Visual Api Training
Visual Api TrainingVisual Api Training
Visual Api Training
Spark Summit
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
CloudxLab
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
Brian O'Neill
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
johnynek
 
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
A deeper-understanding-of-spark-internals
A deeper-understanding-of-spark-internalsA deeper-understanding-of-spark-internals
A deeper-understanding-of-spark-internals
Cheng Min Chi
 
Scalding
ScaldingScalding
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
MongoDB
 
Hello, Guava !
Hello, Guava !Hello, Guava !
Hello, Guava !
輝 子安
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
輝 子安
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
LivePerson
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
Oto Brglez
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian Plosker
SyncConf
 
Polyglot JVM
Polyglot JVMPolyglot JVM
Polyglot JVM
Arturo Herrero
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVMAndres Almiray
 

What's hot (16)

Visual Api Training
Visual Api TrainingVisual Api Training
Visual Api Training
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
 
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Os Davis
Os DavisOs Davis
Os Davis
 
A deeper-understanding-of-spark-internals
A deeper-understanding-of-spark-internalsA deeper-understanding-of-spark-internals
A deeper-understanding-of-spark-internals
 
Scalding
ScaldingScalding
Scalding
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
 
Hello, Guava !
Hello, Guava !Hello, Guava !
Hello, Guava !
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
 
Scalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduceScalding: Reaching Efficient MapReduce
Scalding: Reaching Efficient MapReduce
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian Plosker
 
Polyglot JVM
Polyglot JVMPolyglot JVM
Polyglot JVM
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
 

Viewers also liked

Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Modelling complex game economy with Neo4j by Yan Cui at Codemotion DubaiModelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Codemotion Dubai
 
How to prepare your Enterprise for NoSQL
How to prepare your Enterprise for NoSQLHow to prepare your Enterprise for NoSQL
How to prepare your Enterprise for NoSQL
Tobias Coetzee
 
Ensof photography press kit
Ensof photography press kitEnsof photography press kit
Ensof photography press kit
Jana Yar
 
La oportunidad de la vida
La oportunidad de la vidaLa oportunidad de la vida
La oportunidad de la vida
Jon593
 
Social media management Services for Restuarants
Social media management Services for RestuarantsSocial media management Services for Restuarants
Social media management Services for Restuarants
Real-Time OutSource
 
Como ser un buen
Como ser un buen Como ser un buen
Como ser un buen
Jon593
 
Managing Microservices with Neo4j
Managing Microservices with Neo4jManaging Microservices with Neo4j
Managing Microservices with Neo4j
Ashley Chloe
 
Thursday's Pop Quiz
Thursday's Pop QuizThursday's Pop Quiz
Thursday's Pop Quiz
Heath Fields
 
Child Protection 3
Child Protection 3Child Protection 3
Child Protection 3
sangita_chosencaregroup
 
Person-centred care -10 years of research and practice
Person-centred care -10 years of research and practicePerson-centred care -10 years of research and practice
Person-centred care -10 years of research and practice
Helen Crisp
 
Democracia y medios de comunicación
Democracia y medios de comunicaciónDemocracia y medios de comunicación
Democracia y medios de comunicaciónLuisa Mejía
 
Résumé de théorie et Diagnostic financier et Guide de travaux pratiques
Résumé de théorie et Diagnostic financier et Guide de travaux pratiquesRésumé de théorie et Diagnostic financier et Guide de travaux pratiques
Résumé de théorie et Diagnostic financier et Guide de travaux pratiques
Jamal Yasser
 

Viewers also liked (14)

Cv5
Cv5Cv5
Cv5
 
Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Modelling complex game economy with Neo4j by Yan Cui at Codemotion DubaiModelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
Modelling complex game economy with Neo4j by Yan Cui at Codemotion Dubai
 
How to prepare your Enterprise for NoSQL
How to prepare your Enterprise for NoSQLHow to prepare your Enterprise for NoSQL
How to prepare your Enterprise for NoSQL
 
Ensof photography press kit
Ensof photography press kitEnsof photography press kit
Ensof photography press kit
 
La oportunidad de la vida
La oportunidad de la vidaLa oportunidad de la vida
La oportunidad de la vida
 
Social media management Services for Restuarants
Social media management Services for RestuarantsSocial media management Services for Restuarants
Social media management Services for Restuarants
 
Como ser un buen
Como ser un buen Como ser un buen
Como ser un buen
 
Managing Microservices with Neo4j
Managing Microservices with Neo4jManaging Microservices with Neo4j
Managing Microservices with Neo4j
 
Tabla
TablaTabla
Tabla
 
Thursday's Pop Quiz
Thursday's Pop QuizThursday's Pop Quiz
Thursday's Pop Quiz
 
Child Protection 3
Child Protection 3Child Protection 3
Child Protection 3
 
Person-centred care -10 years of research and practice
Person-centred care -10 years of research and practicePerson-centred care -10 years of research and practice
Person-centred care -10 years of research and practice
 
Democracia y medios de comunicación
Democracia y medios de comunicaciónDemocracia y medios de comunicación
Democracia y medios de comunicación
 
Résumé de théorie et Diagnostic financier et Guide de travaux pratiques
Résumé de théorie et Diagnostic financier et Guide de travaux pratiquesRésumé de théorie et Diagnostic financier et Guide de travaux pratiques
Résumé de théorie et Diagnostic financier et Guide de travaux pratiques
 

Similar to Neo4j

Ruby on Big Data @ Philly Ruby Group
Ruby on Big Data @ Philly Ruby GroupRuby on Big Data @ Philly Ruby Group
Ruby on Big Data @ Philly Ruby Group
Brian O'Neill
 
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.js
Knoldus Inc.
 
Introduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4JIntroduction to Graph Databases with Neo4J
Introduction to Graph Databases with Neo4J
Brant 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 Neo4j
Serendio Inc.
 
Graph Database Query Languages
Graph Database Query LanguagesGraph Database Query Languages
Graph Database Query Languages
Jay Coskey
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle VersionsJeffrey Kemp
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
FITC
 
Neo4j (Part 1)
Neo4j (Part 1)Neo4j (Part 1)
Neo4j (Part 1)
Bibhuti Regmi
 
Scaling Scala to the database - Stefan Zeiger (Typesafe)
Scaling Scala to the database - Stefan Zeiger (Typesafe)Scaling Scala to the database - Stefan Zeiger (Typesafe)
Scaling Scala to the database - Stefan Zeiger (Typesafe)
jaxLondonConference
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
Tanya Cashorali
 
DevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4JDevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4J
Florent Biville
 
ACADILD:: HADOOP LESSON
ACADILD:: HADOOP LESSON ACADILD:: HADOOP LESSON
ACADILD:: HADOOP LESSON
Padma shree. T
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
jeykottalam
 
Soft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4JSoft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4J
Florent Biville
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
Graph Databases, a little connected tour (Codemotion Rome)
Graph Databases, a little connected tour (Codemotion Rome)Graph Databases, a little connected tour (Codemotion Rome)
Graph Databases, a little connected tour (Codemotion Rome)
fcofdezc
 
Graph Database, a little connected tour - Castano
Graph Database, a little connected tour - CastanoGraph Database, a little connected tour - Castano
Graph Database, a little connected tour - Castano
Codemotion
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & CassandraEscape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Piotr Kolaczkowski
 
Graph Database workshop
Graph Database workshopGraph Database workshop
Graph Database workshop
Jeremy Deane
 

Similar to Neo4j (20)

Ruby on Big Data @ Philly Ruby Group
Ruby on Big Data @ Philly Ruby GroupRuby on Big Data @ Philly Ruby Group
Ruby on Big Data @ Philly Ruby Group
 
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.js
 
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
 
Graph Database Query Languages
Graph Database Query LanguagesGraph Database Query Languages
Graph Database Query Languages
 
Old Oracle Versions
Old Oracle VersionsOld Oracle Versions
Old Oracle Versions
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
 
Neo4j (Part 1)
Neo4j (Part 1)Neo4j (Part 1)
Neo4j (Part 1)
 
Scaling Scala to the database - Stefan Zeiger (Typesafe)
Scaling Scala to the database - Stefan Zeiger (Typesafe)Scaling Scala to the database - Stefan Zeiger (Typesafe)
Scaling Scala to the database - Stefan Zeiger (Typesafe)
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
 
DevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4JDevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4J
 
ACADILD:: HADOOP LESSON
ACADILD:: HADOOP LESSON ACADILD:: HADOOP LESSON
ACADILD:: HADOOP LESSON
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
Soft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4JSoft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4J
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
Graph Databases, a little connected tour (Codemotion Rome)
Graph Databases, a little connected tour (Codemotion Rome)Graph Databases, a little connected tour (Codemotion Rome)
Graph Databases, a little connected tour (Codemotion Rome)
 
Graph Database, a little connected tour - Castano
Graph Database, a little connected tour - CastanoGraph Database, a little connected tour - Castano
Graph Database, a little connected tour - Castano
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & CassandraEscape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
Escape from Hadoop: Ultra Fast Data Analysis with Spark & Cassandra
 
Graph Database workshop
Graph Database workshopGraph Database workshop
Graph Database workshop
 

Recently uploaded

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

Neo4j

  • 1. The world's leading graph DB Georgios Eleftheriadis Software/Database Engineer
  • 2. What is NOSQL?  It’s not “No to SQL”  It’s not “Never SQL”  It’s “Not Only SQL” as they may support SQL-like query languages NOSQL describes ongoing trend where developers increasingly opt for non-relational databases to help solve their problems, in an effort to use the right tool for the right job.  NOSQL example databases  Document Oriented (CouchDB, MongoDB)  Key-Value (Memcached, Redis)  Graph Database (Neo4J, InfiniteGraph)  Multi-model (ArangoDB, OrientDB) 2
  • 3. Graphs are everywhere  Relationships in  Politics, Economics, History, Science, Transportation  Biology, Chemistry, Physics, Sociology  Body, Ecosphere, Reaction, Interactions  Internet  Hardware, Software, Interaction  Social Networks  Family, Friends  Work, Communities  Neighbors, Cities, Society 3
  • 4. A sample social graph # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 2ms  with ~1,000 persons  average 50 friends per person  pathExists(a,b) limited to depth 4  caches warmed up to eliminate disk I/O 4
  • 5. A sample social graph # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 2ms  with ~1,000 persons  average 50 friends per person  pathExists(a,b) limited to depth 4  caches warmed up to eliminate disk I/O 5
  • 6. A sample social graph # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 2ms  with ~1,000 persons  average 50 friends per person  pathExists(a,b) limited to depth 4  caches warmed up to eliminate disk I/O 6
  • 7. Two Ways to Work with Neo4j  Embeddable on JVM  Java  Jruby  Scala  Tomcat  Rails  Server with REST API  every language on the planet  flexible deployment scenarios  DIY server or cloud managed Embedded capability == Server capability same scalability, transactionality, and availability 7
  • 8. Pros & Cons with Neo4j Database  Pros  Most of the data is connected  High performance to access connected data  Least or no impact if changes to the data model  Can be mixed with JPA with Spring Data Neo4j  Integrate with Spring  Cons  Could not reuse SQL queries  Migration could be pain  Not effective to use Neo4j if data is not connected 8
  • 9. Enterprise VS Community Edition Features Enterprise Community Property Graph Model YES YES Native Graph Processing & Storage YES YES Cypher – Graph Query Language YES YES Language Drivers YES YES REST & High-Performance Native API YES YES Enterprise Lock Manager YES NO Cache Sharding YES NO Clustered Replication YES NO Hot Backups YES NO Advanced Monitoring YES NO 9
  • 10. RDBMS vs Graph DB 10 ID Name Grade 1510 Jordan 9 1689 Gabriel 9 1381 Tiffany 9 1709 Cassandra 9 1101 Haley 10 1782 Andrew 10 1468 Kris 10 1641 Brittany 10 1247 Alexis 11 1316 Austin 11 1911 Gabriel 11 1501 Jessica 11 1304 Jordan 12 1025 John 12 1934 Kyle 12 1661 Logan 12 ID1 ID2 1510 1381 1510 1689 1689 1709 1381 1247 1709 1247 1689 1782 1782 1468 1782 1316 1782 1304 1468 1101 1468 1641 1101 1641 … … ID1 ID2 1689 1709 1709 1689 1782 1709 1911 1247 1247 1468 1641 1468 1316 1304 1501 1934 1934 1501 1025 1101
  • 11. Cypher Query Language  Declarative query language  Describe what you want, not how  Based on pattern matching 11
  • 12. CQL MATCH  MATCH (a)-->(b) RETURN a, b;  MATCH (a)-->() RETURN a.name;  MATCH (n)-[r]->(m) RETURN n, r, m;  MATCH (a)-[r]->() RETURN id(a), labels(a), keys(a), type(r);  MATCH (a)-[r:ACTED_IN]->(m) RETURN a.name, r.roles, m.title; 12
  • 13. CQL MATCH  MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) RETURN a.name, m.title, d.name;  MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) RETURN a.name AS actor, m.title AS movie, d.name AS director;  MATCH (a)-[:ACTED_IN]->(m) OPTIONAL MATCH (d)-[:DIRECTED]->(m) RETURN a.name, m.title, d.name;  MATCH (a)-[:ACTED_IN]->(m), (d)-[:DIRECTED]->(m) RETURN a.name, m.title, d.name;  MATCH p=(a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) RETURN nodes(p); 13
  • 14. CQL MATCH Functions  count(x) - add up the number of occurrences  min(x) - get the lowest value  max(x) - get the highest value  avg(x) - get the average of a numeric value  collect(x) - collected all the occurrences into an array 14
  • 15. CQL WHERE  MATCH (tom{name:"Tom Hanks"})-[:ACTED_IN]->(movie) WHERE movie.released < 1992 RETURN DISTINCT movie.title;  MATCH (actor{name:"Keanu Reeves"})-[r:ACTED_IN]->(movie) WHERE "Neo" IN r.roles RETURN DISTINCT movie.title;  MATCH (tom{name:"Tom Hanks"})-[:ACTED_IN]->(movie)<-[:ACTED_IN]-(a) WHERE a.born < tom.born RETURN DISTINCT a.name, (tom.born - a.born) AS diff;  MATCH (kevin {name:"Kevin Bacon"})-[:ACTED_IN]->(movie) RETURN DISTINCT movie.title;  MATCH (kevin)-[:ACTED_IN]->(movie) WHERE kevin.name =~ '.*Kevin.*‘ // Regular expressions RETURN DISTINCT movie.title; 15
  • 16. CQL WHERE  MATCH (gene {name:"Gene Hackman"})-[:ACTED_IN]->(movie)<-[:ACTED_IN]-(n) WHERE (n)-[:DIRECTED]->() RETURN DISTINCT n.name;  MATCH (a)-[:ACTED_IN]->() RETURN a.name, count(*) AS count ORDER BY count DESC LIMIT 5;  MATCH (keanu {name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(c), (c)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc) WHERE NOT((keanu)-[:ACTED_IN]->()<-[:ACTED_IN]-(coc)) AND coc <> keanu RETURN coc.name, count(coc) ORDER BY count(coc) DESC LIMIT 3; // Recommend 5 actors that Keanu Reeves should work with (but hasn't) 16
  • 17. CQL CREATE  CREATE ({title:"Mystic River", released:1993});  MATCH (movie {title:"Mystic River"}) SET movie.tagline = "We bury our sins here, Dave. We wash them clean." RETURN movie;  MATCH (kevin {name:"Kevin Bacon"}),(movie {title:"Mystic River"}) CREATE UNIQUE (kevin)-[:ACTED_IN {roles:["Sean"]}]->(movie);  MATCH (kevin {name:"Kevin Bacon"})-[r:ACTED_IN]->(movie {title:"Mystic River"}) SET r.roles = ["Sean Devine"] RETURN r.roles;  MATCH (clint {name:"Clint Eastwood"})-[r:ACTED_IN]->(movie {title:"Mystic River"}) CREATE UNIQUE (clint)-[:DIRECTED]->(movie); 17
  • 18. CQL DELETE  MATCH (matrix {title:"The Matrix"})<-[r:ACTED_IN]-(a) WHERE "Emil" IN r.roles RETURN a; // Emil Eifrem is CEO of Neo Technology and co-founder of the Neo4j project  MATCH (emil{name:"Emil Eifrem"}) DELETE emil;  MATCH (emil{name:"Emil Eifrem"}) -[r]-() DELETE r;  MATCH (emil{name:"Emil Eifrem"}) -[r]-() DELETE r, emil;  MATCH (node) where ID(node)=1 OPTIONAL MATCH (node)-[r]-() DELETE r, node; 18
  • 19. SQL VS Cypher MATCH (keanu:Person { name: 'Keanu Reeves' })-[:ACTED_IN]->(movie:Movie), (director:Person)-[:DIRECTED]->(movie) RETURN director.name, count(*) ORDER BY count(*) DESC 19 SELECT director.name, count(*) FROM person Keanu JOIN acted_in ON keanu.id = acted_in.person_id JOIN directed ON acted_in.movie_id = directed.movie_id JOIN person AS director ON directed.person_id = director.id WHERE keanu.name = 'Keanu Reeves‘ GROUP BY director.name ORDER BY count(*) DESC Now let’s find out a bit about the directors in movies that Keanu Reeves acted in. We want to know how many of those movies each of them directed.
  • 20. CQL INDEXES There is usually no need to specify which indexes to use in a query, Cypher will figure that out by itself. Indexes are also automatically used for equality comparisons and inequality (range) comparisons of an indexed property in the WHERE clause. USING is used to influence the decisions of the planner when building an execution plan for a query.  CREATE INDEX ON :Person(name)  MATCH (person:Person { name: 'Keanu Reeves' }) RETURN person  MATCH (person:Person) WHERE person.name = 'Keanu Reeves' RETURN person  MATCH (person:Person) WHERE person.name > 'Keanu' RETURN person  MATCH (person:Person) WHERE person.name STARTS WITH 'Kea' // CONTAINS, ENDS WITH RETURN person 20
  • 21. Embedded example code GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/neo-4j"); try (Transaction tx = graphDb.beginTx()) { Node firstNode = graphDb.createNode(); firstNode.setProperty("message", "Hello, "); Node secondNode = graphDb.createNode(); secondNode.setProperty("message", "World!"); Relationship relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS); relationship.setProperty("message", "brave Neo4j "); System.out.print(firstNode.getProperty("message")); System.out.print(relationship.getProperty("message")); System.out.print(secondNode.getProperty("message")); tx.success(); } 21
  • 22. Shortest path example code GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/neo-4j"); try (Transaction tx = graphDb.beginTx()) { static Index<Node> indexService = graphDb.index().forNodes("nodes"); Node neo = indexService.get(“name", “Neo").getSingle(); Node agentSmith = indexService.get(“name", "Agent Smith").getSingle(); PathFinder<Path> finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection(KNOWS, Direction.BOTH), 4); Path foundPath = finder.findSinglePath(neo, agentSmith); System.out.println(Paths.simplePathToString(foundPath, NAME_KEY)); } 22
  • 23. CQL Do-It-Yourself  Add KNOWS relationships between all actors who were in the same movie 23  MATCH (a)-[:ACTED_IN]->()<-[:ACTED_IN]-(b) CREATE UNIQUE (a)-[:KNOWS]->(b);  MATCH (a)-[:ACTED_IN|DIRECTED]->()<-[:ACTED_IN|DIRECTED]-(b) CREATE UNIQUE (a)-[:KNOWS]->(b);
  • 24. CQL Useful Tricks  Find friends of friends  MATCH (keanu{name:"Keanu Reeves"})-[:KNOWS*2]->(fof) WHERE NOT((keanu)-[:KNOWS]-(fof)) RETURN DISTINCT fof.name;  Find shortest path  MATCH p=shortestPath( (charlize{name:"Charlize Theron"})-[:KNOWS*]->(bacon{name:"Kevin Bacon"})) RETURN length(rels(p));  Return the names of the people joining Charlize to Kevin.  MATCH p=shortestPath( (charlize{name:"Charlize Theron"})-[:KNOWS*]->(bacon{name:"Kevin Bacon"})) RETURN extract(n IN nodes(p)| n.name) AS names 24
  • 25. CQL Useful Tricks  Find movies and actors up to 4 "hops" away from Kevin Bacon  MATCH (bacon:Person {name:"Kevin Bacon"})-[*1..4]-(hollywood) RETURN DISTINCT Hollywood  Find someone to introduce Tom Hanks to Tom Cruise  MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors), (coActors)-[:ACTED_IN]->(m2)<-[:ACTED_IN]-(cruise:Person {name:"Tom Cruise"}) RETURN tom, m, coActors, m2, cruise 25
  • 26. Social Network Database Relationship Type Properties IS_FRIEND since LIKES WROTE_COMMENT HAS_COMMENT UPLOADED SENT_MESSAGE RECEIVED_MESSAGE TAGGED_IN Node Labels Properties Person name, email, dob Photo caption, date Status text, date Comment text, date Message Text, date 26
  • 27. Social Network Database (2)  CREATE (ann:Person { name: 'Ann', email:'ann@neo.4j', dob:487119060000 }) RETURN ann;  CREATE (john:Person { name: 'John', email:'john@neo.4j', dob:435679060000 }) RETURN john;  MATCH (ann:Person { name: 'Ann' }), (john:Person { name: 'John' }) CREATE UNIQUE (ann)-[:IS_FRIEND{since:'2009'}]-(john);  MATCH (ann:Person { name: 'Ann' }) CREATE (ann)-[:UPLOADED]->(status:Status{text:'Happy Birthday', date:1451610010000});  MATCH (john:Person { name: 'John' }), (status:Status{text:'Happy Birthday'}) CREATE (john)-[:LIKES]->(status); 27
  • 28. Social Network Database (3)  MATCH (john:Person { name: 'John' }) CREATE (john)-[:UPLOADED]->(photo:Photo{text:'Birthday Party', date:1452410019386});  MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'}) CREATE (ann)-[:LIKES]->(photo);  MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'}) CREATE (ann)-[:WROTE_COMMENT]->(comment:Comment{text:'Happy Birthday. The party was great!', date:1452410478569})<-[:HAS_COMMENT]-(photo);  MATCH (ann:Person { name: 'Ann' }), (photo:Photo{text:'Birthday Party'}) CREATE (ann)-[:TAGGED_IN]->(photo); 28
  • 29. Social Network Database (4)  MATCH (john:Person { name: 'John' }) RETURN (john)-[:UPLOADED]->(:Photo);  MATCH (ann:Person { name: 'Ann' }) -[:LIKES]->(photo:Photo) RETURN ann, photo;  MATCH (ann:Person { name: 'Ann' })-[:IS_FRIEND]-(:Person)-[:UPLOADED]-(photo:Photo) RETURN ann, photo  MATCH (ann:Person { name: 'Ann' })-[:IS_FRIEND]-(friend:Person), (friend:Person)-[:UPLOADED]-(photo:Photo) RETURN ann, photo, friend 29
  • 30. How to get started?  Documentation  http://neo4j.com/docs/ - tutorials & reference  Neo4j in Action  Graph Databases by O'Reilly  Get Neo4j  http://neo4j.org/download  http://elements.heroku.com/addons/graphenedb  Participate  http://groups.google.com/group/neo4j  http://neo4j.meetup.com  http://stackoverflow.com/questions/tagged/neo4j 30