an introduction to neo4j

23
Neo4j Introduction the basic stuff

Upload: thoughtworks

Post on 15-Jul-2015

1.558 views

Category:

Software


2 download

TRANSCRIPT

Page 1: An Introduction to Neo4j

Neo4j Introduction

the basic stuff

Page 2: An Introduction to Neo4j

Agenda

● What / Why

● Learn through an FoF example

● More involved problem: Which airport

performans better

● Advance modeling topics

Page 3: An Introduction to Neo4j

What is it?

A Graph Database

Page 4: An Introduction to Neo4j

A Graph Database

Page 5: An Introduction to Neo4j

Relational Model

Page 6: An Introduction to Neo4j

In Graph

Page 7: An Introduction to Neo4j

Why Graph Database

Page 8: An Introduction to Neo4j

● Wicked fast on a type of problem

● Scale up independent of amount of data

● Intuitive modeling

● Fun and Freedom (embedded mode)

Page 9: An Introduction to Neo4j

Setup (on a mac)

$> brew update

$> brew install neo4j

$> neo4j start

$> open http://localhost:7474

Page 10: An Introduction to Neo4j

3 way to use

* Standalone with Cypher *

* Server plugin

* Embedded

Page 11: An Introduction to Neo4j

Cypher

is the way get stuff out from Neo4j graph

Page 12: An Introduction to Neo4j

A FoF example covers

Create

Match

Where

Count

Order by

Page 13: An Introduction to Neo4j

Create node/relationship

create(joe:Person {name: Joe” })

create(sara:Person {name: “Sara” })

create joe-[:knows]->sara

Page 14: An Introduction to Neo4j

Who is Joe’s friend?

MATCH (joe { name: 'Joe' })-[:knows]-(friends)

RETURN joe, friends

Page 15: An Introduction to Neo4j

Joe’s friends of friends

MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)

RETURN fof

Page 16: An Introduction to Neo4j

Wait, Joe already knows sara

MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)

WHERE NOT(joe-[:knows]-fof)

RETURN fof

Page 17: An Introduction to Neo4j

Who is more likely to be Joe's

friend?

MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)

WHERE NOT(joe-[:knows]-fof)

RETURN fof.name, count(*)

ORDER BY count(*) DESC, fof.name

Page 18: An Introduction to Neo4j

A flight/airport example

http://gist.neo4j.org/?6619085

Page 19: An Introduction to Neo4j

Data From

http://www.transtats.bts.gov/DL_SelectFields.a

sp?Table_ID=236&DB_Short_Name=On-Time

Page 20: An Introduction to Neo4j

Data model

Page 21: An Introduction to Neo4j

Ask questions

● How many flight canceled

● How many flight delayed

● Average taxi waiting time

● Shortest path between

Page 22: An Introduction to Neo4j

Other way to use neo4j

● Embedded (CTA)

● Server plugin (Grok)

Page 23: An Introduction to Neo4j

Neo4j modeling tips

● Understand the performance character○ Traversing is fast

○ IO is slow

○ Node properties are lazy loaded/cached

● Normalization verse denormalization in

relational database performance tuning