neo4j graph data modeling

Post on 26-Jan-2015

118 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Kenny demonstrates how to build a flexible and expressive graph model and related queries that map closely to your domain needs, and which can be evolved as your application evolves.

TRANSCRIPT

(graphs)-[:are]->(everywhere)

Graph����������� ������������������  Data����������� ������������������  ModelingNeo4j

© All Rights Reserved 2014 | Neo Technology, Inc.

with����������� ������������������  @kennybastani

© All Rights Reserved 2014 | Neo Technology, Inc.

Agenda

•What����������� ������������������  is����������� ������������������  a����������� ������������������  graph����������� ������������������  database?����������� ������������������  

•Introduction����������� ������������������  to����������� ������������������  graphs����������� ������������������  

•Introduction����������� ������������������  to����������� ������������������  the����������� ������������������  labeled����������� ������������������  property����������� ������������������  graph����������� ������������������  data����������� ������������������  model����������� ������������������  

•Introduction����������� ������������������  to����������� ������������������  Cypher����������� ������������������  (Neo4j’s����������� ������������������  query����������� ������������������  language)����������� ������������������  

•Tour����������� ������������������  of����������� ������������������  the����������� ������������������  Neo4j����������� ������������������  browser����������� ������������������  

•Introduction����������� ������������������  to����������� ������������������  graph-based����������� ������������������  modeling����������� ������������������  

•Graph����������� ������������������  data����������� ������������������  modeling����������� ������������������  guidelines����������� ������������������  

•Authoring����������� ������������������  a����������� ������������������  GraphGist

2

© All Rights Reserved 2014 | Neo Technology, Inc.

(What����������� ������������������  is����������� ������������������  a����������� ������������������  graph����������� ������������������  database?)

© All Rights Reserved 2014 | Neo Technology, Inc.

What����������� ������������������  is����������� ������������������  a����������� ������������������  graph����������� ������������������  database?

•Graph����������� ������������������  databases����������� ������������������  are����������� ������������������  a����������� ������������������  kind����������� ������������������  of����������� ������������������  NoSQL����������� ������������������  database����������� ������������������  

•It����������� ������������������  lets����������� ������������������  you����������� ������������������  store����������� ������������������  and����������� ������������������  manage����������� ������������������  your����������� ������������������  data����������� ������������������  as����������� ������������������  a����������� ������������������  graph����������� ������������������  

•Graphs����������� ������������������  are����������� ������������������  a����������� ������������������  set����������� ������������������  of����������� ������������������  nodes����������� ������������������  and����������� ������������������  relationships����������� ������������������  that����������� ������������������  describe����������� ������������������  some����������� ������������������  arbitrary����������� ������������������  domain����������� ������������������  

•Neo4j����������� ������������������  is����������� ������������������  a����������� ������������������  graph����������� ������������������  database,����������� ������������������  using����������� ������������������  the����������� ������������������  labeled����������� ������������������  graph����������� ������������������  property����������� ������������������  data����������� ������������������  model

4

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

(Introduction����������� ������������������  to����������� ������������������  graphs)

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

What����������� ������������������  is����������� ������������������  a����������� ������������������  graph?

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Zombie Pastimes

Eating Brains

Dancing With Michael Jackson

% of People Who Hate Michael Jackson by Date

0

25

50

75

100

June 25, 2009 June 26,2009

7

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Zombie Pastimes

Eating Brains

Dancing WithMichael Jackson

% of People Who Hate Michael Jackson by Date

0

25

50

75

100

June 25, 2009 June 26,2009

These

����������� ������������������  are����������� ������������������  C

harts!

NOT����������� ������������������  G

raphs!

8

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

So����������� ������������������  what����������� ������������������  about����������� ������������������  data?

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

John

Sally

Graph Databases Book

Friend Of

Friend Of

Has Rea

d

Has Read

10

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

name: John age: 27

name: Sally age: 32

title: Graph Databases authors: Ian Robinson, Jim Webber

FRIEND_OF since: 01/09/2013

HAS_READ on: 2/03/2013 rating: 5

HAS_READ on: 02/09/2013 rating: 4

FRIEND_OF since: 01/09/2013

11

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

The����������� ������������������  Relational����������� ������������������  Table����������� ������������������  Model

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Customers AccountsCustomer_Accounts

143 Alice 326 $100

725 $632

981 $212

143 981

143 725

143 326

13

© All Rights Reserved 2014 | Neo Technology, Inc.

(Introduction����������� ������������������  to����������� ������������������  the����������� ������������������  labeled����������� ������������������  property����������� ������������������  graph����������� ������������������  data����������� ������������������  model)

© All Rights Reserved 2014 | Neo Technology, Inc.

Four����������� ������������������  Building����������� ������������������  Blocks

•Nodes����������� ������������������  

•Relationships����������� ������������������  

•Properties����������� ������������������  

•Labels

15

© All Rights Reserved 2014 | Neo Technology, Inc.

Nodes

16

© All Rights Reserved 2014 | Neo Technology, Inc.

Nodes

•Nodes����������� ������������������  are����������� ������������������  used����������� ������������������  to����������� ������������������  represent����������� ������������������  en##es  and  complex  value  types  in����������� ������������������  your����������� ������������������  domain����������� ������������������  

•Nodes����������� ������������������  contain����������� ������������������  properties����������� ������������������  

•Key-value����������� ������������������  pairs����������� ������������������  

• Java����������� ������������������  primitives����������� ������������������  

• Arrays����������� ������������������  

• null����������� ������������������  is����������� ������������������  not����������� ������������������  a����������� ������������������  valid����������� ������������������  value����������� ������������������  

•Every����������� ������������������  node����������� ������������������  can����������� ������������������  have����������� ������������������  different����������� ������������������  properties����������� ������������������  

•Nodes����������� ������������������  do����������� ������������������  not����������� ������������������  have����������� ������������������  to����������� ������������������  have����������� ������������������  the����������� ������������������  same����������� ������������������  keys

17

© All Rights Reserved 2014 | Neo Technology, Inc.

Relationships

18

© All Rights Reserved 2014 | Neo Technology, Inc.

Relationships����������� ������������������  (continued)

19

Nodes  can  have  more  than  one  relationship

Self  relationships  are  allowed

Nodes  can  be  connected  by  more  than  one  relationship

© All Rights Reserved 2014 | Neo Technology, Inc.

Relationships

•Every����������� ������������������  relationship����������� ������������������  has����������� ������������������  a����������� ������������������  name����������� ������������������  and����������� ������������������  a����������� ������������������  direc#on  •Add����������� ������������������  structure����������� ������������������  to����������� ������������������  the����������� ������������������  graph����������� ������������������  

•Provide����������� ������������������  semantic����������� ������������������  context����������� ������������������  for����������� ������������������  nodes����������� ������������������  

•Can����������� ������������������  contain����������� ������������������  properties����������� ������������������  

•Used����������� ������������������  to����������� ������������������  represent����������� ������������������  quality����������� ������������������  or����������� ������������������  weight  of����������� ������������������  relationship,����������� ������������������  or����������� ������������������  metadata����������� ������������������  

•Every����������� ������������������  relationship����������� ������������������  must����������� ������������������  have����������� ������������������  a����������� ������������������  start  node����������� ������������������  and����������� ������������������  end  node  •No����������� ������������������  dangling����������� ������������������  relationships

20

© All Rights Reserved 2014 | Neo Technology, Inc.

Labels

21

© All Rights Reserved 2014 | Neo Technology, Inc.

Labels

•Every����������� ������������������  node����������� ������������������  can����������� ������������������  have����������� ������������������  zero  or  more  labels����������� ������������������  

•Used����������� ������������������  to����������� ������������������  represent����������� ������������������  roles����������� ������������������  (e.g.����������� ������������������  user,����������� ������������������  product,����������� ������������������  company)����������� ������������������  

•Group����������� ������������������  nodes����������� ������������������  

•Allow����������� ������������������  us����������� ������������������  to����������� ������������������  associate����������� ������������������  indexes����������� ������������������  and����������� ������������������  constraints����������� ������������������  with����������� ������������������  groups����������� ������������������  of����������� ������������������  nodes

22

© All Rights Reserved 2014 | Neo Technology, Inc.

Four����������� ������������������  Building����������� ������������������  Blocks

•Nodes����������� ������������������  

•Entities����������� ������������������  

•Relationships����������� ������������������  

•Connect����������� ������������������  entities����������� ������������������  and����������� ������������������  structure����������� ������������������  domain����������� ������������������  

•Properties����������� ������������������  

•Entity����������� ������������������  attributes,����������� ������������������  relationship����������� ������������������  qualities,����������� ������������������  and����������� ������������������  metadata����������� ������������������  

•Labels����������� ������������������  

•Group����������� ������������������  nodes����������� ������������������  by����������� ������������������  role

23

© All Rights Reserved 2014 | Neo Technology, Inc.

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

© All Rights Reserved 2014 | Neo Technology, Inc.

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

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

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

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

25

© All Rights Reserved 2014 | Neo Technology, Inc.

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

26

A

B C

© All Rights Reserved 2014 | Neo Technology, Inc.27

© All Rights Reserved 2014 | Neo Technology, Inc.28

© All Rights Reserved 2014 | Neo Technology, Inc.

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

© All Rights Reserved 2014 | Neo Technology, Inc.

(a) --> (b)

a b

Text����������� ������������������  Art

30

© All Rights Reserved 2014 | Neo Technology, Inc.

Either����������� ������������������  direction

31

MATCH (a)--(b)

RETURN a, b;

a b

© All Rights Reserved 2014 | Neo Technology, Inc.

Direction����������� ������������������  specific

32

MATCH (a)-->(b)

RETURN a, b;

a b

© All Rights Reserved 2014 | Neo Technology, Inc.33

b

a

b

a

b

a

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

© All Rights Reserved 2014 | Neo Technology, Inc.

(a) -[r]-> ()

a

Relationships

34

r

© All Rights Reserved 2014 | Neo Technology, Inc.

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

35

MATCH (a)-[r]->()

RETURN a.name, type(r);

ar

© All Rights Reserved 2014 | Neo Technology, Inc.

(a) -[:ACTED_IN]-> (m)

a m

Actors����������� ������������������  and����������� ������������������  movies

36

ACTED IN

© All Rights Reserved 2014 | Neo Technology, Inc.

Return����������� ������������������  properties����������� ������������������  of����������� ������������������  the����������� ������������������  matched����������� ������������������  pattern

37

MATCH (a)-[:ACTED_IN]->(m)

RETURN a.name, m.title;

a mACTED IN

© All Rights Reserved 2014 | Neo Technology, Inc.

Also����������� ������������������  return����������� ������������������  properties����������� ������������������  of����������� ������������������  the����������� ������������������  relationship

38

MATCH (a)-[r:ACTED_IN]->(m)

RETURN a.name, r.roles, m.title;

a mACTED IN

© All Rights Reserved 2014 | Neo Technology, Inc.

Paths

39

(a)-->(b)-->(c)

a b c

© All Rights Reserved 2014 | Neo Technology, Inc.40

b

c

a

b

c

a

b

a

(a)-->(b)-->(c)

© All Rights Reserved 2014 | Neo Technology, Inc.

Paths

41

(a)-->(b)-->(c)

a b c

© All Rights Reserved 2014 | Neo Technology, Inc.

Paths

42

(a)-->(b)<--(c)

a b c

© All Rights Reserved 2014 | Neo Technology, Inc.43

c

b

a

c

b

c

b

a

a(a)-->(b)<--(c)

© All Rights Reserved 2014 | Neo Technology, Inc.

Who����������� ������������������  acted����������� ������������������  in����������� ������������������  a����������� ������������������  movie����������� ������������������  and����������� ������������������  who����������� ������������������  was����������� ������������������  the����������� ������������������  director����������� ������������������  of����������� ������������������  that����������� ������������������  movie?

44

MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)

RETURN a.name, m.title, d.name;

a

mACTED IN

dDIRECTED

© All Rights Reserved 2014 | Neo Technology, Inc.45

MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) RETURN a.name, m.title, d.name;

d

m

a

d

m

d

m

a

a

© All Rights Reserved 2014 | Neo Technology, Inc.

Table����������� ������������������  of����������� ������������������  results

46

MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)

RETURN a.name, m.title, d.name;

a.name m.title d.name“Keanu Reeves” “The Matrix” “Andy Wachowski”“Keanu Reeves” “The Matrix Reloaded” “Andy Wachowski”“Noah Wyle” “A Few Good Men” “Rob Reiner”“Tom Hanks” “Cloud Atlas” “Andy Wachowski”

... ... ...

© All Rights Reserved 2014 | Neo Technology, Inc.

Many����������� ������������������  aggregation����������� ������������������  functions����������� ������������������  are����������� ������������������  supported

47

count(x) - add up the number of occurrencesmin(x) - get the lowest valuemax(x) - get the highest valueavg(x) - get the average of a numeric valuesum(x) - add up all values

collect(x) - collected all the occurrences into an array

© All Rights Reserved 2014 | Neo Technology, Inc.

MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d)

RETURN a.name, d.name, count(*) AS count

ORDER BY count DESC

LIMIT 5;

Sort����������� ������������������  &����������� ������������������  Limit

48

Which����������� ������������������  actor����������� ������������������  and����������� ������������������  director����������� ������������������  worked����������� ������������������  together����������� ������������������  the����������� ������������������  most?

© All Rights Reserved 2014 | Neo Technology, Inc.

Graph����������� ������������������  Traversal����������� ������������������  (Getting����������� ������������������  from����������� ������������������  point����������� ������������������  A����������� ������������������  to����������� ������������������  point����������� ������������������  ����������� ������������������  B)

© All Rights Reserved 2014 | Neo Technology, Inc.

All-nodes����������� ������������������  Query

50

MATCH (n) RETURN n;

Matches every node in the graph

© All Rights Reserved 2014 | Neo Technology, Inc.

Find����������� ������������������  a����������� ������������������  specific����������� ������������������  node����������� ������������������  (within����������� ������������������  all-nodes)

51

MATCH (n)

WHERE n.name = "Tom Hanks"

RETURN n;

WHERE - filter the results

n.name = "Tom Hanks" - by the name property value

© All Rights Reserved 2014 | Neo Technology, Inc.

Find����������� ������������������  a����������� ������������������  specific����������� ������������������  node����������� ������������������  (concise����������� ������������������  syntax)

52

MATCH (n {name:"Tom Hanks"})

RETURN n;

MATCH (n) - find patterns in graph

{name:"Tom Hanks"} - with the specified properties

© All Rights Reserved 2014 | Neo Technology, Inc.53

MATCH (n {n.name:"Tom Hanks"}) RETURN n;

t

© All Rights Reserved 2014 | Neo Technology, Inc.

Find����������� ������������������  a����������� ������������������  specific����������� ������������������  node����������� ������������������  (with����������� ������������������  a����������� ������������������  label)

54

MATCH (tom:Person)

WHERE tom.name="Tom Hanks"

RETURN tom;

:Person - Matches only nodes labeled as Person

© All Rights Reserved 2014 | Neo Technology, Inc.55

MATCH (tom:Person {name:"Tom Hanks"}) RETURN tom;

t

© All Rights Reserved 2014 | Neo Technology, Inc.

Start����������� ������������������  with����������� ������������������  a����������� ������������������  specific����������� ������������������  (labeled)����������� ������������������  node

56

MATCH (tom:Person)-[:ACTED_IN]->(movie:Movie)

WHERE tom.name="Tom Hanks"

RETURN movie.title;

(Movies featuring Tom Hanks)

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(movie:Movie)

RETURN movie.title;

© All Rights Reserved 2014 | Neo Technology, Inc.57

m

m

m

t

m

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(movie:Movie) RETURN movie.title;

© All Rights Reserved 2014 | Neo Technology, Inc.

Start����������� ������������������  with����������� ������������������  a����������� ������������������  specific����������� ������������������  labeled����������� ������������������  node

58

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(movie),

(director)-[:DIRECTED]->(movie)

RETURN director.name;

(Directors who worked with Tom Hanks)

© All Rights Reserved 2014 | Neo Technology, Inc.59

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(movie:Movie) (director:Person)-[:DIRECTED]->(movie)

RETURN director.name;

t

d

d

© All Rights Reserved 2014 | Neo Technology, Inc.

(Tour����������� ������������������  of����������� ������������������  the����������� ������������������  Neo4j����������� ������������������  browser)

© All Rights Reserved 2014 | Neo Technology, Inc.

http://localhost:7474/

Neo4j����������� ������������������  Browser����������� ������������������  -����������� ������������������  finding����������� ������������������  help

61

© All Rights Reserved 2014 | Neo Technology, Inc.

Neo4j����������� ������������������  Browser����������� ������������������  Execute����������� ������������������  Cypher,����������� ������������������  Visualize

62

© All Rights Reserved 2014 | Neo Technology, Inc.

Neo4j����������� ������������������  Browser����������� ������������������  -����������� ������������������  importing����������� ������������������  sample����������� ������������������  data

63

© All Rights Reserved 2014 | Neo Technology, Inc.

Neo4j����������� ������������������  Data����������� ������������������  browser����������� ������������������  -����������� ������������������  display����������� ������������������  more����������� ������������������  data

64

© All Rights Reserved 2014 | Neo Technology, Inc.

(Graph����������� ������������������  search����������� ������������������  and����������� ������������������  Neo4j)

© All Rights Reserved 2014 | Neo Technology, Inc.

© All Rights Reserved 2014 | Neo Technology, Inc.67

MATCH (me:Person {name:’Philip’})-[:FRIEND_OF]->(friends), (friends)-[:LIKES]->(restaurant), (restaurant)-[:LOCATED_IN]->(city {Location = ‘New York’}),

(restaurant)-[:SERVES]->(cuisine {cuisine = ‘Sushi’}) RETURN restaurant.name

* Cypher query language example

© All Rights Reserved 2014 | Neo Technology, Inc.68

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

(Introduction����������� ������������������  to����������� ������������������  graph-based����������� ������������������  modeling)

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Start����������� ������������������  with����������� ������������������  a����������� ������������������  whiteboard

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.71

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Adam

LOL Cat

FRIEND_OFSHARED

COMMENTED

SarahFUNNY

ON

LIKES

72

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Adam

LOL Cat

FRIEND_OFSHARED

COMMENTED

SarahFUNNY

ON

LIKES

73

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.74

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Tom Hanks Hugo Weaving

Cloud AtlasThe Matrix

Lana Wachowski

ACTED_IN

ACTED_INACTED_IN

DIRECTED

DIRECTED75

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Model����������� ������������������  Incrementally

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

Tom Hanks Hugo Weaving

Cloud AtlasThe Matrix

Lana Wachowski

ACTED_IN

ACTED_INACTED_IN

DIRECTED

DIRECTED77

© All Rights Reserved 2014 | Neo Technology, Inc.© All Rights Reserved 2013 | Neo Technology, Inc.© All Rights Reserved 2014 | Neo Technology, Inc.

name: Tom Hanks nationality: USA won: Oscar, Emmy

name: Hugo Weaving nationality: Australia won: MTV Movie Award

title: Cloud Atlas genre: drama, sci-fi

title: The Matrix genre: sci-fi

name: Lana Wachowski nationality: USA won: Razzie, Hugo

ACTED_IN role: Zachry

ACTED_IN role: Bill Smoke

DIRECTED

DIRECTED

ACTED_IN role: Agent Smith

78

© All Rights Reserved 2014 | Neo Technology, Inc.

(Graph����������� ������������������  data����������� ������������������  modeling����������� ������������������  guidelines)

© All Rights Reserved 2014 | Neo Technology, Inc.

Symmetric����������� ������������������  Relationships

80

OR

© All Rights Reserved 2014 | Neo Technology, Inc.

Infer����������� ������������������  Symmetric����������� ������������������  Relationship

Find  child:MATCH (parent{name:'Sarah'})����������� ������������������   -[:PARENT_OF]->(child)����������� ������������������  RETURN child����������� ������������������  Find  parent:  MATCH (parent)-[:PARENT_OF]->����������� ������������������   (child{name:'Eric'})����������� ������������������  RETURN parent

81

© All Rights Reserved 2014 | Neo Technology, Inc.

Bi-Directional����������� ������������������  Relationships

82

© All Rights Reserved 2014 | Neo Technology, Inc.

Use����������� ������������������  Single����������� ������������������  Relationship����������� ������������������  and����������� ������������������  Ignore����������� ������������������  Relationship����������� ������������������  Direction����������� ������������������  in����������� ������������������  Queries

MATCH (p1{name:'Eric'}) -[:KNOWS]-(p2)RETURN p2

83

© All Rights Reserved 2014 | Neo Technology, Inc.

Qualified����������� ������������������  Bi-Directional����������� ������������������  Relationships

84

OR

© All Rights Reserved 2014 | Neo Technology, Inc.

Properties����������� ������������������  Versus����������� ������������������  Relationships

85

© All Rights Reserved 2014 | Neo Technology, Inc.

Use����������� ������������������  Relationships����������� ������������������  When

•You����������� ������������������  need����������� ������������������  to����������� ������������������  specify����������� ������������������  the����������� ������������������  weight,����������� ������������������  strength,����������� ������������������  or����������� ������������������  some����������� ������������������  other����������� ������������������  quality����������� ������������������  of����������� ������������������  the����������� ������������������  rela#onship  and����������� ������������������  the����������� ������������������  nodes����������� ������������������  it����������� ������������������  connects  

•The����������� ������������������  property����������� ������������������  value����������� ������������������  comprises����������� ������������������  a����������� ������������������  complex����������� ������������������  value����������� ������������������  type����������� ������������������  (e.g.����������� ������������������  address)����������� ������������������  

•Examples:����������� ������������������  

•Find����������� ������������������  all����������� ������������������  my����������� ������������������  colleagues����������� ������������������  who����������� ������������������  are����������� ������������������  level  2  or  above  in����������� ������������������  a����������� ������������������  skill  (property����������� ������������������  value)����������� ������������������  we����������� ������������������  have����������� ������������������  in����������� ������������������  common����������� ������������������  

•Find����������� ������������������  all����������� ������������������  recent����������� ������������������  orders����������� ������������������  delivered����������� ������������������  to����������� ������������������  the����������� ������������������  same����������� ������������������  delivery  address����������� ������������������  (complex����������� ������������������  value����������� ������������������  type)

86

© All Rights Reserved 2014 | Neo Technology, Inc.

Example:����������� ������������������  Find����������� ������������������  Expert����������� ������������������  Colleagues

87

© All Rights Reserved 2014 | Neo Technology, Inc.

Use����������� ������������������  Properties����������� ������������������  When

•There’s����������� ������������������  no����������� ������������������  need����������� ������������������  to����������� ������������������  qualify/weight����������� ������������������  the����������� ������������������  relationship����������� ������������������  

•The����������� ������������������  property����������� ������������������  value����������� ������������������  comprises����������� ������������������  a����������� ������������������  simple����������� ������������������  value����������� ������������������  type����������� ������������������  (e.g.����������� ������������������  color)����������� ������������������  

•Examples:����������� ������������������  

•Find����������� ������������������  those����������� ������������������  projects����������� ������������������  written����������� ������������������  by����������� ������������������  contributors����������� ������������������  to����������� ������������������  my����������� ������������������  projects����������� ������������������  that����������� ������������������  use����������� ������������������  the����������� ������������������  same����������� ������������������  language����������� ������������������  (property����������� ������������������  value)����������� ������������������  as����������� ������������������  my����������� ������������������  projects

88

© All Rights Reserved 2014 | Neo Technology, Inc.

Relationship����������� ������������������  Granularity

89

© All Rights Reserved 2014 | Neo Technology, Inc.

General����������� ������������������  Relationships

•Qualified����������� ������������������  by����������� ������������������  property

90

© All Rights Reserved 2014 | Neo Technology, Inc.

Specific����������� ������������������  Relationships

91

© All Rights Reserved 2014 | Neo Technology, Inc.

Best����������� ������������������  of����������� ������������������  Both����������� ������������������  Worlds

92

© All Rights Reserved 2014 | Neo Technology, Inc.

(The����������� ������������������  Neo4j����������� ������������������  GraphGist����������� ������������������  Project)

© All Rights Reserved 2014 | Neo Technology, Inc.

The����������� ������������������  Neo4j����������� ������������������  GraphGist����������� ������������������  Project

94

GraphGists let you demonstrate a Neo4j graph proof of concept for your use cases

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Start����������� ������������������  by����������� ������������������  articulating����������� ������������������  your����������� ������������������  problem

95

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Introduction����������� ������������������  to����������� ������������������  Problem����������� ������������������  

!

•Banks����������� ������������������  and����������� ������������������  Insurance����������� ������������������  companies����������� ������������������  lose����������� ������������������  billions����������� ������������������  of����������� ������������������  dollars����������� ������������������  every����������� ������������������  year����������� ������������������  to����������� ������������������  fraud.����������� ������������������  Traditional����������� ������������������  methods����������� ������������������  of����������� ������������������  fraud����������� ������������������  detection����������� ������������������  play����������� ������������������  an����������� ������������������  important����������� ������������������  role����������� ������������������  in����������� ������������������  minimizing����������� ������������������  these����������� ������������������  losses.����������� ������������������  However����������� ������������������  increasingly����������� ������������������  sophisticated����������� ������������������  fraudsters����������� ������������������  have����������� ������������������  developed����������� ������������������  a����������� ������������������  variety����������� ������������������  of����������� ������������������  ways����������� ������������������  to����������� ������������������  elude����������� ������������������  discovery,����������� ������������������  both����������� ������������������  by����������� ������������������  working����������� ������������������  together,����������� ������������������  and����������� ������������������  by����������� ������������������  leveraging����������� ������������������  various����������� ������������������  other����������� ������������������  means����������� ������������������  of����������� ������������������  constructing����������� ������������������  false����������� ������������������  identities.

96

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Explanation����������� ������������������  of����������� ������������������  Solution����������� ������������������  

!

•Graph����������� ������������������  databases����������� ������������������  offer����������� ������������������  new����������� ������������������  methods����������� ������������������  of����������� ������������������  uncovering����������� ������������������  fraud����������� ������������������  rings����������� ������������������  and����������� ������������������  other����������� ������������������  sophisticated����������� ������������������  scams����������� ������������������  with����������� ������������������  a����������� ������������������  high-level����������� ������������������  of����������� ������������������  accuracy,����������� ������������������  and����������� ������������������  are����������� ������������������  capable����������� ������������������  of����������� ������������������  stopping����������� ������������������  advanced����������� ������������������  fraud����������� ������������������  scenarios����������� ������������������  in����������� ������������������  real-time.

97

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Design����������� ������������������  a����������� ������������������  graph����������� ������������������  model����������� ������������������  ����������� ������������������  

•Describe����������� ������������������  the����������� ������������������  entities����������� ������������������  and����������� ������������������  relationships����������� ������������������  sufficient����������� ������������������  enough����������� ������������������  to����������� ������������������  express����������� ������������������  your����������� ������������������  domain����������� ������������������  and����������� ������������������  solve����������� ������������������  your����������� ������������������  problem

98

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

99

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Translate����������� ������������������  your����������� ������������������  graph����������� ������������������  model����������� ������������������  design����������� ������������������  into����������� ������������������  Cypher

100

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

101

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Formulate����������� ������������������  your����������� ������������������  questions����������� ������������������  to����������� ������������������  solve����������� ������������������  the����������� ������������������  problem

•Which����������� ������������������  account����������� ������������������  holders����������� ������������������  share����������� ������������������  more����������� ������������������  than����������� ������������������  one����������� ������������������  piece����������� ������������������  of����������� ������������������  legitimate����������� ������������������  contact����������� ������������������  information?����������� ������������������  

•What’s����������� ������������������  the����������� ������������������  financial����������� ������������������  risk����������� ������������������  of����������� ������������������  a����������� ������������������  possible����������� ������������������  fraud����������� ������������������  ring?

102

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Translate����������� ������������������  your����������� ������������������  questions����������� ������������������  into����������� ������������������  Cypher����������� ������������������  queries����������� ������������������  on����������� ������������������  your����������� ������������������  graph����������� ������������������  data����������� ������������������  model

103

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Which����������� ������������������  account����������� ������������������  holders����������� ������������������  share����������� ������������������  more����������� ������������������  than����������� ������������������  one����������� ������������������  piece����������� ������������������  of����������� ������������������  legitimate����������� ������������������  contact����������� ������������������  information?

104

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Summary����������� ������������������  

•Introduction����������� ������������������  to����������� ������������������  the����������� ������������������  problem����������� ������������������  

•Explanation����������� ������������������  of����������� ������������������  the����������� ������������������  solution����������� ������������������  

•Design����������� ������������������  a����������� ������������������  graph����������� ������������������  data����������� ������������������  model����������� ������������������  

•Translate����������� ������������������  your����������� ������������������  graph����������� ������������������  data����������� ������������������  model����������� ������������������  into����������� ������������������  a����������� ������������������  Cypher����������� ������������������  dataset����������� ������������������  

•Formulate����������� ������������������  your����������� ������������������  questions����������� ������������������  to����������� ������������������  solve����������� ������������������  the����������� ������������������  problem����������� ������������������  

•Translate����������� ������������������  your����������� ������������������  questions����������� ������������������  into����������� ������������������  Cypher����������� ������������������  queries����������� ������������������  on����������� ������������������  your����������� ������������������  graph����������� ������������������  data����������� ������������������  model����������� ������������������  

•Iterate����������� ������������������  design����������� ������������������  until����������� ������������������  the����������� ������������������  graph����������� ������������������  data����������� ������������������  model����������� ������������������  answers����������� ������������������  the����������� ������������������  questions

105

© All Rights Reserved 2014 | Neo Technology, Inc.

Authoring����������� ������������������  a����������� ������������������  GraphGist

•Get����������� ������������������  started����������� ������������������  at����������� ������������������  http://gist.neo4j.org

106

© All Rights Reserved 2014 | Neo Technology, Inc.

(Thank����������� ������������������  You)

© All Rights Reserved 2014 | Neo Technology, Inc.

Get����������� ������������������  in����������� ������������������  touch

Twitter: @kennybastani

LinkedIn: /in/kennybastani

Email: kenny.bastani@neotechnology.com

top related