Hands on Neo4j 2.0

51
Hands on Neo4j 2.0 Dr. Jim Webber Chief Scientist, Neo Technology @jimwebber

description

Neo4j is the world's leading graph database, and with the advent of the new, shiny 2.0.x releases it's time to get into it.

Transcript of Hands on Neo4j 2.0

Page 1: Hands on Neo4j 2.0

Hands on Neo4j 2.0

Dr. Jim Webber!Chief Scientist, Neo Technology!

@jimwebber

Page 2: Hands on Neo4j 2.0

roadmap• where we are (mostly)

• imprisoned data

• a little history

• labeled property graph model

• connected data

• using a whiteboard

http://flickr.com/photos/23465812@N00/7898643042 by davecito, CC BY

Page 3: Hands on Neo4j 2.0

Neo Technology, Inc Confidential Drupal8 Schema - Copyright drupal.org

Page 4: Hands on Neo4j 2.0

Neo Technology, Inc Confidential

TABLES?

ARGGHHH

Page 5: Hands on Neo4j 2.0

Neo Technology, Inc Confidentialhttp://flickr.com/photos/keepingtime_ca/8490224742 by keepingtime_ca, CC BY

Page 6: Hands on Neo4j 2.0

Neo Technology, Inc ConfidentialBy AgnosticPreachersKid (Own work) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons

Page 7: Hands on Neo4j 2.0

Neo Technology, Inc Confidential http://flickr.com/photos/rueful/5917659410/ by Kiran Foster, CC BY

Page 8: Hands on Neo4j 2.0

“There is a significant downside - the whole approach works really well when data access is aligned with the aggregates, but what if you want to look at the data in a different way? Order entry naturally stores orders as

aggregates, but analyzing product sales cuts across the aggregate structure. The advantage of not using an aggregate structure in the

database is that it allows you to slice and dice your data different ways for different audiences.

!

This is why aggregate-oriented stores talk so much about map-reduce.”

– Martin Fowler, http://martinfowler.com/bliki/AggregateOrientedDatabase.html

Page 9: Hands on Neo4j 2.0

Neo Technology, Inc Confidentialhttp://flickr.com/photos/wwworks/5319295174 by woodleywonderworks, CC BY

Page 10: Hands on Neo4j 2.0
Page 11: Hands on Neo4j 2.0
Page 12: Hands on Neo4j 2.0

Neo Technology, Inc Confidential Copyright TFL (Transport For London)

Page 13: Hands on Neo4j 2.0

Leonhard Euler(1707 - 1783)

Image by Jakob Emanuel Handmann [Public domain], via Wikimedia Commons

Page 14: Hands on Neo4j 2.0

Neo Technology, Inc Confidential Image is US Public Domain

A

B

D

C

Page 15: Hands on Neo4j 2.0

A

B

D

C

Page 16: Hands on Neo4j 2.0

http://flickr.com/photos/samchurchill/8022804713 by Sam Churchill, CC BY

Page 17: Hands on Neo4j 2.0

Copyright Facebook

Page 18: Hands on Neo4j 2.0

[CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons

Page 19: Hands on Neo4j 2.0

By Euan Richard (Own work) [CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons

Page 20: Hands on Neo4j 2.0

% of People Who Hate Michael Jackson by Date

0

25

50

75

100

June 25, 2009 June 26,2009

Not a Graph

Page 21: Hands on Neo4j 2.0

Customers AccountsCustomer_Accounts

143 Alice

143 326

143 725

143 981

326 $100

725 $632

981 $212

Page 22: Hands on Neo4j 2.0

name: Alice

bal: $100

bal: $632

bal: $212

Nodes

Relationships

owns

owns

owns

Customer

Account

Account

Account

Page 23: Hands on Neo4j 2.0

Labeled Property Graph Model

• Nodes with optional labels and optional properties

• Named, directed Relationships with optional properties

(Relationships have exactly one start and one end node, which may be the same node)

Page 24: Hands on Neo4j 2.0

modelingstart with a whiteboard

Page 25: Hands on Neo4j 2.0
Page 26: Hands on Neo4j 2.0
Page 27: Hands on Neo4j 2.0
Page 28: Hands on Neo4j 2.0
Page 29: Hands on Neo4j 2.0
Page 30: Hands on Neo4j 2.0
Page 31: Hands on Neo4j 2.0
Page 32: Hands on Neo4j 2.0

Flight_Delayid

flight_iddelay_timereason_id

Airportid

namecity_id

Cityid

name

Flightid

dateflight_number

origin_airport_iddestination_airport_idscheduled_departure

scheduled_arrivalReason

idname

Flight_Diversionid

flight_idairport_id

Page 33: Hands on Neo4j 2.0

SELECT r.name as reason, count(*) as result_count FROM Flight f INNER JOIN Airport o ON Airport.id = Flight.origin_airport_id, INNER JOIN Airport d ON Airport.id = Flight.destination_airport_id, INNER JOIN Flight_Delay fd ON Airport.id = Flight_Delay.flight_id INNER JOIN Reason r ON Flight_Delay.reason_id = Reason.id WHERE o.name = "SFO" AND d.name = "JFK" GROUP BY r.name ORDER BY result_count DESC

Fail

Page 34: Hands on Neo4j 2.0
Page 35: Hands on Neo4j 2.0
Page 36: Hands on Neo4j 2.0

(o)<-[:ORIGIN]-(f) (f)-[:

DESTIN

ATION]

->(d)

(f)-[:CANCELLED_BY]->(r)

Page 37: Hands on Neo4j 2.0

(o)<-[:ORIGIN]-(f) (f)-[:DESTINATION]->(d)

(f)-[:CANCELLED_BY]->(r)

MATCH , ,

WHERE o.code = "SFO" AND d.code = "JFK"

RETURN r.name AS reason, count(*) AS count

ORDER BY count DESC

Page 38: Hands on Neo4j 2.0

MATCH (o)<-[:ORIGIN]-(f)-[:DESTINATION]->(d),

(f)-[:CANCELLED_BY]->(r)

WHERE o.code = "SFO" AND d.code = "JFK"

RETURN r.name AS reason, count(*) AS count

ORDER BY count DESC

Page 39: Hands on Neo4j 2.0
Page 40: Hands on Neo4j 2.0
Page 41: Hands on Neo4j 2.0
Page 42: Hands on Neo4j 2.0
Page 43: Hands on Neo4j 2.0
Page 44: Hands on Neo4j 2.0
Page 45: Hands on Neo4j 2.0
Page 46: Hands on Neo4j 2.0

MATCH  (customer)-­‐[:BOUGHT]-­‐>()-­‐[:IN*]-­‐>(:Category  {name:'Baby'}),  

           (customer)-­‐[:BOUGHT]-­‐>()-­‐[:IN*]-­‐>(:Category  {name:'Beer'})  

WHERE  NOT  (customer)-­‐[:BOUGHT]-­‐>()-­‐[:IN*]-­‐>(:Category  {name:'Console'})  

RETURN  customer

Page 47: Hands on Neo4j 2.0

A Demo?Using Neo4j 2.0.3 for Retail Analytics in minutes

Page 48: Hands on Neo4j 2.0

What’s Neo4j good for?• Recommendations

• Social networks

• Content Management

• MDM / System-of-Record

• Product Catalogue

• Financial Audit / Modeling

• Business intelligence

• Data centre management

• Supply chain/provenance

• Routing

• Web of things

• Time series/event data

• Web analytics, user journeys

• Scientific computing

• Spatial

• Geo/Seismic/Meteorological

• Bio/Pharma

• And much, much more…

Page 49: Hands on Neo4j 2.0

Aviation

Finance

Accenture

AerospaceEnergy

Software Financial Telecoms Health Web / Social Media Education, Logistics,

Government

Network & Data Center

MDM / SystemOf Record

Social

Geo

Recommendations

Identity &Access Control

ContentManagement

Business Intel.,Audit, CRM

Page 50: Hands on Neo4j 2.0

Resources

• Graph Databases Book (O’Reilly)

• Full, free eBook version available:http://graphdatabases.com

• New, free online training:

• http://www.neo4j.org/learn/online_course

Page 51: Hands on Neo4j 2.0

@jimwebber [email protected]

Questions?

And big thanks to eSynergy for hosting!