intro to neo4j 2.0
DESCRIPTION
A short intro on Neo4j 2.0, Cypher and some community use-casesTRANSCRIPT
�1
Peter Neubauer @peterneubauer #neo4j
Introduction to NoSQL & Neo4j
�1
Peter Neubauer @peterneubauer #neo4j
Neo4j
Introduction to NoSQL & Neo4j
�1
�2
The Path Forward
�2
The Path Forward
1.Some things about Neo4j.
�2
The Path Forward
1.Some things about Neo4j.
2.Programming lang examples
�2
The Path Forward
1.Some things about Neo4j.
2.Programming lang examples
3.Cypher
�2
The Path Forward
1.Some things about Neo4j.
2.Programming lang examples
3.Cypher
4.How do people use Neo4j?
�2
�3
�3
Everyone is talking about graphs...
�3
Everyone is talking about graphs...
Facebook Open Graph
�3
Everyone is talking about graphs...
Facebook Open Graph
Neo Technology, Inc Confidential
Core Industries & Use Cases:
Web / ISV Finance & Insurance
Datacom / Telecom
Network & Data Center Management
MDM
Social
Geo
Early Adopter Segments(What we expected to happen - view from several years ago)
Neo Technology, Inc Confidential*Community Users Not Included
Core Industries & Use Cases:
Web / ISV Financial Services
Telecomm-unications
Network & Data Center Management
MDM
Social
Geo
Select Commercial Customers* Across Anticipated SegmentsNeo4j Adoption Snapshot
Neo Technology, Inc Confidential
Core Industries & Use Cases:
Web / ISV Finance & Insurance
Telecomm-unications
Network & Data Center Management
MDM
Social
Geo
Select Commercial Customers* Across Anticipated SegmentsNeo4j Adoption Snapshot
Neo Technology, Inc Confidential
Core Industries & Use Cases:
Web / ISV Finance & Insurance
Telecomm-unications
Network & Data Center Management
MDM
Social
Geo
Select Commercial Customers* Across Anticipated SegmentsNeo4j Adoption Snapshot
Core Industries & Use Cases: Software
Financial Services
Telecommunications
Health Care & Life Sciences
Web Social,HR & Recruiting
Media & Publishing
Energy, Services, Automotive, Gov’t, Logistics, Education,
Gaming, Other
Network & Data Center Management
MDM / System of Record
Social
Geo
Recommend-ations
Identity & Access Mgmt
Content Management
BI, CRM, Impact Analysis, Fraud Detection, Resource
Optimization, etc.
Accenture
Finance
Energy Aerospace
Graph DB 101
�7
A graph database...
���8
A graph database...
���8
NO: not for charts & diagrams, or vector artwork
A graph database...
���8
NO: not for charts & diagrams, or vector artwork
YES: for storing data that is structured as a graph
A graph database...
���8
NO: not for charts & diagrams, or vector artwork
YES: for storing data that is structured as a graph
remember linked lists, trees?
A graph database...
���8
NO: not for charts & diagrams, or vector artwork
YES: for storing data that is structured as a graph
remember linked lists, trees?
graphs are the general-purpose data structure
A graph database...
���8
NO: not for charts & diagrams, or vector artwork
YES: for storing data that is structured as a graph
remember linked lists, trees?
graphs are the general-purpose data structure
“A relational database may tell you the average age of everyone in this session,
but a graph database will tell you who is most likely to buy you a beer.”
�9
You know relational
�9
You know relational
�9
You know relational
�9
foo
You know relational
�9
foo bar
You know relational
�9
foo barfoo_bar
You know relational
�9
foo barfoo_bar
You know relational
�9
foo barfoo_bar
You know relational
�9
foo barfoo_bar
You know relational
�9
now consider relationships...
You know relational
�9
now consider relationships...
You know relational
�9
now consider relationships...
You know relational
�9
now consider relationships...
You know relational
�9
now consider relationships...
You know relational
�9
now consider relationships...
�9
�10
We're talking about a Property Graph
�10
We're talking about a Property Graph
�10
Nodes
We're talking about a Property Graph
�10
Nodes
Relationships
Emil
Andrés
Lars
Johan
Allison
Peter
Michael
Tobias
Andreas
IanMica
Delia
knows
knows
knowsknows
knows
knows
knows
knows
knows
knowsMica
knowsknowsMica
Delia
knows
We're talking about a Property Graph
�10
Nodes
Relationships
Properties (each a key+value)
Labels (constraints, Indexes for look-ups)
�11
Looks different, fine. Who cares?
�11
Looks different, fine. Who cares?
๏a sample social graph
�11
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
�11
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
�11
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
๏pathExists(a,b) limited to depth 4
�11
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
๏pathExists(a,b) limited to depth 4
๏caches warmed up to eliminate disk I/O
�11
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
๏pathExists(a,b) limited to depth 4
๏caches warmed up to eliminate disk I/O
�11
# persons query time
Relational database 1 000 2000ms
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
๏pathExists(a,b) limited to depth 4
๏caches warmed up to eliminate disk I/O
�11
# persons query time
Relational database 1 000 2000ms
Neo4j 1 000 2ms
Looks different, fine. Who cares?
๏a sample social graph
•with ~1,000 persons
๏average 50 friends per person
๏pathExists(a,b) limited to depth 4
๏caches warmed up to eliminate disk I/O
�11
# persons query time
Relational database 1 000 2000ms
Neo4j 1 000 2ms
Neo4j 1 000 000 2ms
�11
Graph Database: Pros & Cons๏Strengths
•Powerful data model, as general as RDBMS
•Fast, for connected data
•Easy to query
๏Weaknesses:
•Sharding (though they can scale reasonably well)
‣also, stay tuned for developments here
•Requires conceptual shift
‣though graph-like thinking becomes addictive
�12
Show me some code, pleaseShow me some code, please
GraphDatabaseService graphDb = new EmbeddedGraphDatabase(“var/neo4j”);
Transaction tx = graphDb.beginTx();try { Node steve = graphDb.createNode(); Node michael = graphDb.createNode();! steve.setProperty(“name”, “Steve Vinoski”); michael.setProperty(“name”, “Michael Hunger”);! Relationship presentedWith = steve.createRelationshipTo( michael, PresentationTypes.PRESENTED_WITH); presentedWith.setProperty(“date”, today); tx.success();} finally { tx.finish();}
Java Traversal Framework
for ( Path position : Traversal.description() .depthFirst() .relationships( Rels.KNOWS ) .relationships( Rels.LIKES, Direction.INCOMING ) .evaluator( Evaluators.toDepth( 5 ) ) .traverse( node ) ){ output += position + "\n";}
Spring Data Neo4j@NodeEntitypublic class Movie { @Indexed private String title; @RelatedToVia(type = “ACTS_IN”, direction=INCOMING) private Set<Role> cast; private Director director;}!@NodeEntitypublic class Actor { @RelatedTo(type = “ACTS_IN”) private Set<Movies> movies;}!@RelationshipEntitypublic class Role { @StartNode private Actor actor; @EndNode private Movie movie; private String roleName;}
neo4j.rbgem install neo4j
!require 'rubygems' require 'neo4j' !class Person include Neo4j::NodeMixin property :name, :age, :rank index :name has_n :friends end !Neo4j::Transaction.run do neo = Person.new :name=>'Neo', :age=>29 morpheus = Person.new :name=>'Morpheus', :rank=>'Captain' neo.friends << morpheus end !neo.friends.each {|p|...}
�17
And, but, so how do youquery this "graph" database?
�17
© All Rights Reserved 2013 | Neo Technology, Inc.
(Introduction����������� ������������������ to����������� ������������������ Cypher)
Neo Technology, Inc Confidential
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher����������� ������������������ is����������� ������������������ Neo4j's����������� ������������������ graph����������� ������������������ query����������� ������������������ language
Neo Technology, Inc Confidential
© All Rights Reserved 2013 | Neo Technology, Inc.
•Declarative����������� ������������������ Pattern-Matching����������� ������������������ language����������� ������������������
•SQL-like����������� ������������������ syntax����������� ������������������
•Designed����������� ������������������ for����������� ������������������ graphs
© All Rights Reserved 2013 | Neo Technology, Inc.
It’s����������� ������������������ all����������� ������������������ about����������� ������������������ Patterns
A
B C
Neo Technology, Inc Confidential
© All Rights Reserved 2013 | Neo Technology, Inc.
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo Technology, Inc Confidential
© All Rights Reserved 2013 | Neo Technology, Inc.
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo Technology, Inc Confidential
© All Rights Reserved 2013 | Neo Technology, Inc.
© All Rights Reserved 2013 | Neo Technology, Inc.
© All Rights Reserved 2013 | Neo Technology, Inc.
How?����������� ������������������
© All Rights Reserved 2013 | Neo Technology, Inc.
a b
Two����������� ������������������ nodes,����������� ������������������ one����������� ������������������ relationship
© All Rights Reserved 2013 | Neo Technology, Inc.
(a) --> (b)
a b
Two����������� ������������������ nodes,����������� ������������������ one����������� ������������������ relationship
© All Rights Reserved 2013 | Neo Technology, Inc.
Two����������� ������������������ nodes,����������� ������������������ one����������� ������������������ relationship
MATCH (a)--(b) RETURN a, b;
a b
�27
Andreas
Query a graph with a pattern
�27
Andreas
Query a graph with a pattern
�27
// then traverse to find results MATCH (n:People)--()--(foaf) WHERE n.name = ‘Andreas’ RETURN foaf
�27
Bindings
�28
REST://
Neo4j in the wild
�29
�30
Neo4j in the wild
�31
Neo4j in the wild
�32
Neo4j in the wild
�33
Neo4j in the wild
�34
Neo4j in the wild
�35
Neo4j in the wild
�36
Neo4j in the wild
�37
Neo4j in the wild
�38
Neo4j in the wild
�39
Neo4j in the wild
�40
Neo4j in the wild
�41
Neo4j in the wild
�42
Neo4j in the wild
�43
Neo4j in the wild
�44
Neo4j in the wild
�45
Neo4j in the wild
�46
Neo4j in the wild
�47
Neo4j in the wild
�48
Neo4j in the wild
�49
Thank you!
�50