intro to neo4j 2.0

101
1 Peter Neubauer @peterneubauer #neo4j Introduction to NoSQL & Neo4j

Upload: peter-neubauer

Post on 16-May-2015

845 views

Category:

Technology


1 download

DESCRIPTION

A short intro on Neo4j 2.0, Cypher and some community use-cases

TRANSCRIPT

Page 1: Intro to Neo4j 2.0

�1

Peter Neubauer @peterneubauer #neo4j

Introduction to NoSQL & Neo4j

Page 2: Intro to Neo4j 2.0

�1

Peter Neubauer @peterneubauer #neo4j

Neo4j

Introduction to NoSQL & Neo4j

Page 3: Intro to Neo4j 2.0

�1

Page 4: Intro to Neo4j 2.0

�2

Page 5: Intro to Neo4j 2.0

The Path Forward

�2

Page 6: Intro to Neo4j 2.0

The Path Forward

1.Some things about Neo4j.

�2

Page 7: Intro to Neo4j 2.0

The Path Forward

1.Some things about Neo4j.

2.Programming lang examples

�2

Page 8: Intro to Neo4j 2.0

The Path Forward

1.Some things about Neo4j.

2.Programming lang examples

3.Cypher

�2

Page 9: Intro to Neo4j 2.0

The Path Forward

1.Some things about Neo4j.

2.Programming lang examples

3.Cypher

4.How do people use Neo4j?

�2

Page 10: Intro to Neo4j 2.0

�3

Page 11: Intro to Neo4j 2.0

�3

Everyone is talking about graphs...

Page 12: Intro to Neo4j 2.0

�3

Everyone is talking about graphs...

Facebook Open Graph

Page 13: Intro to Neo4j 2.0

�3

Everyone is talking about graphs...

Facebook Open Graph

Page 14: Intro to Neo4j 2.0

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)

Page 15: Intro to Neo4j 2.0

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

Page 16: Intro to Neo4j 2.0

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

Page 17: Intro to Neo4j 2.0

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

Page 18: Intro to Neo4j 2.0

Graph DB 101

�7

Page 19: Intro to Neo4j 2.0

A graph database...

���8

Page 20: Intro to Neo4j 2.0

A graph database...

���8

NO: not for charts & diagrams, or vector artwork

Page 21: Intro to Neo4j 2.0

A graph database...

���8

NO: not for charts & diagrams, or vector artwork

YES: for storing data that is structured as a graph

Page 22: Intro to Neo4j 2.0

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?

Page 23: Intro to Neo4j 2.0

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

Page 24: Intro to Neo4j 2.0

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.”

Page 25: Intro to Neo4j 2.0

�9

Page 26: Intro to Neo4j 2.0

You know relational

�9

Page 27: Intro to Neo4j 2.0

You know relational

�9

Page 28: Intro to Neo4j 2.0

You know relational

�9

foo

Page 29: Intro to Neo4j 2.0

You know relational

�9

foo bar

Page 30: Intro to Neo4j 2.0

You know relational

�9

foo barfoo_bar

Page 31: Intro to Neo4j 2.0

You know relational

�9

foo barfoo_bar

Page 32: Intro to Neo4j 2.0

You know relational

�9

foo barfoo_bar

Page 33: Intro to Neo4j 2.0

You know relational

�9

foo barfoo_bar

Page 34: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 35: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 36: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 37: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 38: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 39: Intro to Neo4j 2.0

You know relational

�9

now consider relationships...

Page 40: Intro to Neo4j 2.0

�9

Page 41: Intro to Neo4j 2.0

�10

Page 42: Intro to Neo4j 2.0

We're talking about a Property Graph

�10

Page 43: Intro to Neo4j 2.0

We're talking about a Property Graph

�10

Nodes

Page 44: Intro to Neo4j 2.0

We're talking about a Property Graph

�10

Nodes

Relationships

Page 45: Intro to Neo4j 2.0

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)

Page 46: Intro to Neo4j 2.0

�11

Page 47: Intro to Neo4j 2.0

Looks different, fine. Who cares?

�11

Page 48: Intro to Neo4j 2.0

Looks different, fine. Who cares?

๏a sample social graph

�11

Page 49: Intro to Neo4j 2.0

Looks different, fine. Who cares?

๏a sample social graph

•with ~1,000 persons

�11

Page 50: Intro to Neo4j 2.0

Looks different, fine. Who cares?

๏a sample social graph

•with ~1,000 persons

๏average 50 friends per person

�11

Page 51: Intro to Neo4j 2.0

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

Page 52: Intro to Neo4j 2.0

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

Page 53: Intro to Neo4j 2.0

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

Page 54: Intro to Neo4j 2.0

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

Page 55: Intro to Neo4j 2.0

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

Page 56: Intro to Neo4j 2.0

�11

Page 57: Intro to Neo4j 2.0

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

Page 58: Intro to Neo4j 2.0

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();}

Page 59: Intro to Neo4j 2.0

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";}

Page 60: Intro to Neo4j 2.0

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;}

Page 61: Intro to Neo4j 2.0

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|...}

Page 62: Intro to Neo4j 2.0

�17

Page 63: Intro to Neo4j 2.0

And, but, so how do youquery this "graph" database?

�17

Page 64: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

(Introduction����������� ������������������  to����������� ������������������  Cypher)

Page 65: Intro to Neo4j 2.0

Neo Technology, Inc Confidential

© All Rights Reserved 2013 | Neo Technology, Inc.

Cypher����������� ������������������  is����������� ������������������  Neo4j's����������� ������������������  graph����������� ������������������  query����������� ������������������  language

Page 66: Intro to Neo4j 2.0

Neo Technology, Inc Confidential

© All Rights Reserved 2013 | Neo Technology, Inc.

•Declarative����������� ������������������  Pattern-Matching����������� ������������������  language����������� ������������������  

•SQL-like����������� ������������������  syntax����������� ������������������  

•Designed����������� ������������������  for����������� ������������������  graphs

Page 67: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

It’s����������� ������������������  all����������� ������������������  about����������� ������������������  Patterns

A

B C

Page 68: Intro to Neo4j 2.0

Neo Technology, Inc Confidential

© All Rights Reserved 2013 | Neo Technology, Inc.

© All Rights Reserved 2013 | Neo Technology, Inc.

Page 69: Intro to Neo4j 2.0

Neo Technology, Inc Confidential

© All Rights Reserved 2013 | Neo Technology, Inc.

© All Rights Reserved 2013 | Neo Technology, Inc.

Page 70: Intro to Neo4j 2.0

Neo Technology, Inc Confidential

© All Rights Reserved 2013 | Neo Technology, Inc.

© All Rights Reserved 2013 | Neo Technology, Inc.

Page 71: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

How?����������� ������������������  

Page 72: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

a b

Two����������� ������������������  nodes,����������� ������������������  one����������� ������������������  relationship

Page 73: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

(a) --> (b)

a b

Two����������� ������������������  nodes,����������� ������������������  one����������� ������������������  relationship

Page 74: Intro to Neo4j 2.0

© All Rights Reserved 2013 | Neo Technology, Inc.

Two����������� ������������������  nodes,����������� ������������������  one����������� ������������������  relationship

MATCH (a)--(b) RETURN a, b;

a b

Page 75: Intro to Neo4j 2.0

�27

Page 76: Intro to Neo4j 2.0

Andreas

Query a graph with a pattern

�27

Page 77: Intro to Neo4j 2.0

Andreas

Query a graph with a pattern

�27

// then traverse to find results MATCH (n:People)--()--(foaf) WHERE n.name = ‘Andreas’ RETURN foaf

Page 78: Intro to Neo4j 2.0

�27

Page 79: Intro to Neo4j 2.0

Bindings

�28

REST://

Page 80: Intro to Neo4j 2.0

Neo4j in the wild

�29

Page 81: Intro to Neo4j 2.0

�30

Page 82: Intro to Neo4j 2.0

Neo4j in the wild

�31

Page 83: Intro to Neo4j 2.0

Neo4j in the wild

�32

Page 84: Intro to Neo4j 2.0

Neo4j in the wild

�33

Page 85: Intro to Neo4j 2.0

Neo4j in the wild

�34

Page 86: Intro to Neo4j 2.0

Neo4j in the wild

�35

Page 87: Intro to Neo4j 2.0

Neo4j in the wild

�36

Page 88: Intro to Neo4j 2.0

Neo4j in the wild

�37

Page 89: Intro to Neo4j 2.0

Neo4j in the wild

�38

Page 90: Intro to Neo4j 2.0

Neo4j in the wild

�39

Page 91: Intro to Neo4j 2.0

Neo4j in the wild

�40

Page 92: Intro to Neo4j 2.0

Neo4j in the wild

�41

Page 93: Intro to Neo4j 2.0

Neo4j in the wild

�42

Page 94: Intro to Neo4j 2.0

Neo4j in the wild

�43

Page 95: Intro to Neo4j 2.0

Neo4j in the wild

�44

Page 96: Intro to Neo4j 2.0

Neo4j in the wild

�45

Page 97: Intro to Neo4j 2.0

Neo4j in the wild

�46

Page 98: Intro to Neo4j 2.0

Neo4j in the wild

�47

Page 99: Intro to Neo4j 2.0

Neo4j in the wild

�48

Page 100: Intro to Neo4j 2.0

Neo4j in the wild

�49

Page 101: Intro to Neo4j 2.0

Thank you!

�50