SlideShare a Scribd company logo
1 of 70
Download to read offline
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphdatenbanken mit Neo4j
Modell - Einsatz - Abfrage mit Cypher - Use-Cases - 2.0
Stefan Plantikow
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Guten Tag
• Entwickler bei neo technology
• Kernel und Abfragesprache
• Neo4j 1.9
• Neo4j 2.0-M04
@boggle
github.com/boggle
stefan.plantikow@neotechnology.com
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Trends
• Big Data
„data sets so large and complex that it becomes difficult to process using
on-hand database management tools“
• Grösser
• Vernetzter
• Vielfältiger
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
NoSQL
Komplexität Grösse
Key-Value-Store Gering Gross
Column-Store Mittel Mittel bis gross
Document-Store Mittel Mittel
Graphdatenbank Sehr hoch Mittel
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
NoSQLComplexity
Column
Family
Size
Key-Value
Store
Document
Databases
Graph
Databases
90%
of
use
cases
RDBMS
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphs != Charts
Graph DB Kenntnisse
Kennen
Graph DBs
Kennen keine
Graph DBs
Charts != Graphs
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Gerichteter Graph
me
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Beispielgraphen
diamond butterfly bullstar
franklin horton hall-jankorobertson
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Beispielgraphen
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphen
• Knoten („Dinge“)
• Kanten/Relationships („Beziehungen“, oft gerichtet)
• Mathematik: Multigraphen, Hypergraphen, Probabilistische Graphen, ...
• Graphdatenbanken: Property Graphs (Gerichteter Multigraph mit Properties)
• Key-Value Properties: Name, Letzter Login, Anzahl Posts, ...
• Label: Person, Artikel, Vorgang, ...
• Indices: Exakt nach Namen, Volltext nach Beschreibung, ...
2.0
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Property Graphs
name:
Stefan
id: @gmail
title:
Cloud Atlas
type:
Book
:ORDERED
copies: 5
when: 2012
name:
Chris
id: @gmail
:FRIEND
since: 2013
title:
Cloud Atlas
type:
Movie
:BROWSED
times: 100
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
name:
Stefan
id: @gmail
title:
Cloud Atlas
type:
Book
:ORDERED
copies: 5
when: 2012
name:
Chris
id: @gmail
:FRIEND
since: 2013
title:
Cloud Atlas
type:
Movie
:BROWSED
times: 100
Labeled Property Graphs
Customer
Customer
Article
Article
TopHit
High Volume
2.0
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Beispielanfrage
• Für einen Nutzer mit dem Namen
„Stefan“,
finde alle Artikel die sich seine
Freunde mindestens 4x angesehen
haben und
liefere sie nach Häufigkeit sortiert
zurück.
• Ausgehend von Knoten und Kanten
im Graph
Finde Muster im Graph und
berechne daraus das Ergebnis
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Beispielanfrage
• START n=node(*)
MATCH (n {name: „Stefan“),
MATCH (n)-[:FRIEND]->(f),
(f)-[r:VIEWED]->(a)
WHERE r.browsed >= 4
RETURN a
ORDER BY r.browsed
• Ausgehend von Knoten und Kanten
im Graph
Finde Muster im Graph und
berechne daraus das Ergebnis
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Beispielanfrage: Indexe, Muster, Ergebnis
• Wie kommt man „in den Graph“?
• Knoten- bzw. Kanten-Id
• Indexe:
Exakt, Volltext, Geospatial,
Custom
• Muster
• Einschränkungen an Knoten und
Kanten
und ihre Verbindungen
• Ergebnis
• Sortieren
• Aggregieren
• Filtern & Umwandeln
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Vorteile von Graphen
• Natürliches und mächtiges Datenmodell
• Schnelles, problemfreies Object Mapping
• Strukturelle Abfragen sind einfach
• Beziehungen sind Modellelement 1. Klasse (nicht: implizite Joins)
• Erweiterbares einheitliches Modell für alle Daten
• Neue Properties
• Beziehungen zwischen vorher unverbundenen Daten
• Erfordert Umdenken!
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Typische Anwendungen
• Social Networks &
Recommendations
• Geospatial
• Infrastructure as a Service
• Business Intelligence
• Content Management
• Access Control
• Bioinformatics
• Genealogie
• Telco
• Finance
• ...
(Fast) Alles ;) aber insbesondere:
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Modellierung
• Von der Domäne zum Graph
• Von der (relationalen) Anwendung zum Graph
• Vergleich relationales Modellieren mit Modellierung im Graph
• How-to-Model
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling
Am Anfang ist das Whiteboard
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling
• Vom Use-Case zum Datenbankschema
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling (1)
name:
Adam
image:
lolcat1.gif
name:
Sarah
:SHARES :FRIEND_OF
:LIKES
text:
Funny!
:COMMENTED:ABOUT
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling (2)
name:
Adam
id: adam@
image:
lolcat1.gif
downloads:
5.000.000
name:
Sarah
:SHARES
:FRIEND_OF
since: 1995
:LIKES
text:
Funny!
source:
mobile
:COMMENTED
when: 2013:ABOUT
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling (3)
name:
Adam
id: adam@
text:
Look at this!
on:
Mar-2013
name:
Sarah
:SHARED
:FRIEND_OF
since: 1995
:LIKES
text:
Funny!
source:
mobile
:COMMENTED
when: 2013
:ABOUT
image:
lolcat1.gif
downloads:
5.000.000
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Whiteboard Modelling (4)
name:
Adam
id: adam@
text:
Look at this!
on:
Mar-2013
name:
Sarah
:SHARED
:FRIEND_OF
since: 1995
:LIKES
text:
Funny!
source:
mobile
:COMMENTED
when: 2013
:ABOUT
image:
lolcat1.gif
downloads:
5.000.000
2.0
User
User
Post
CommentPost
FileResource
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphen aus Relationen (1)
Customers AccountsCustomer_Accounts
143 Alice
326
$100
725
$632
981 $212
143 981
143 725
143 326
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphen aus Relationen (2)
Alice
$100
$632
$212
143
326
725
981
143 981
143 725
143 326
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphen aus Relationen (3)
name: Alice
bal: $100
bal: $212
Nodes
Relationships
owns
owns
owns
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
What language do they speak here?
Language Country
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
What language do they speak here?
Language Country
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Tables (1)
language_code
language_name
word_count
Language
country_code
country_name
flag_uri
language_code
Country
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Tables (2)
language_code
language_name
word_count
country_code
Language
country_code
country_name
flag_uri
Country
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Tables (3)
language_code
language_name
word_count
Language
country_code
country_name
flag_uri
Country
language_code
country_code
LanguageCountry
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Tables (4)
language_code
language_name
word_count
Language
country_code
country_name
flag_uri
Country
language_code
country_code
primary
LanguageCountry
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Graphs (1)
name
word_count
Language
name
flag_uri
Country
IS_SPOKEN_IN
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Languages in Graphs (2)
name
word_count
Language
name
flag_uri
Country
IS_SPOKEN_IN
as_primary
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Unterschied: Languages in Tabellen vs. Graphs
language_code
language_name
word_count
Language
country_code
country_name
flag_uri
Country
language_code
country_code
primary
LanguageCountry
IS_SPOKEN_IN
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
How To Model
• Normalisierung: Erst in einem Knoten sammeln - dann Aufteilen
• ggf. Kanten einfügen um Relevantes zu verbinden
• ggf. Properties in Kanten wandeln und umgekehrt
• Unverbundene Knoten vermeiden
• Zusätzliche Zugriffspfade anlegen, z.B.
• zeitlich sortierte Linked List für Posts
• „Abkürzungen“
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphdatenbanken
• NoSQL Datenbank
• Speichert Property Graph Modell
• zusätzliche Indexe
• ggf. Label
• Performance Definition:
Bei steigender Knotenanzahl selber Aufwand für einen „Schritt“ im Graphen
(in-memory)
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphdatenbanken
• Performance Definition:
Bei steigender Knotenanzahl selber Aufwand für einen „Schritt“ im Graphen
(in-memory)
• Social Graph mit 50 „Freunden“ pro Nutzer im Durchschnitte
• Suche nach Freunden 4. Grades nach Datenbank-Warmup
DB # Nutzer Zeit
Relational 1.000 2000 ms
Neo4j 1.000 2 ms
Neo4j 1.000.000 2 ms
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo4j
• Dual-Licensed: Open Source (AGPL) / Kommerziell
• Transaktional (ACID)
• Read-Committed
(Serializable durch explizites Locking)
• Server mit Web-UI
• High Availability (Online Backup, Replikation)
• Tooling: Shell, Backup, ...
• Umfangreiche Community & Kommerzieller Support
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo4j Browser
Nach Installation: http://localhost:7474
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo4j Console
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Online Demo: console.neo4j.org
Ausprobieren:
start	
  n=node(*)	
  match	
  n-­‐[r:LOVES]-­‐>m	
  return	
  n,	
  type(r),	
  m
(rote	
  Knoten	
  sind	
  Ergebnisknoten)
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo4j
• Dual-Licensed: Open Source (AGPL) / Kommerziell
• Transaktional (ACID)
• Read-Committed
(Serializable durch explizites Locking)
• Server mit Web-UI
• High Availability
• Tooling: Shell, Backup, Monitoring (JMX), ...
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Neo4j Implementation
• Kernel: Java
Web-UI: Javascript
• kaum Dependencies
• kernel.jar: 2MB
• DirectByteBuffer
• GC-resistent custom caches
• Anfragesprache Cypher: Scala 2.10
• Runtime mit Kernel integriert
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Einsatz
• Anfragesprache Cypher
• Embedded Database: Java Core API
• Eingebettet in Application Container
oder eigene Middleware
• Server: REST API
• Custom Server Extensions
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Schnittstellen
• Neo4j
• Java Core API
• REST API
• Graph Frameworks
• Spring Data Graph
• Blueprints Neo4j
• Third Party Language Drivers
• JDBCS
• Ruby
• Javascript
• .NET
• Clojure
• Python...
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Java Core API Operationen
• Transaktionen
• Knoten und Kanten anlegen
• Index Lookup
• Traversierung
• GlobalGraphOperations (alle Knoten etc.)
• Zusätzliche APIs:
A*, Custom Traversers, Batch Insertion, Transaction Handler
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Java Core API: Knoten und Kanten einfügen
• GraphDatabaseService = new EmbeddedGraphDatabase( "var/graphDb" );
Transaction tx = gds.beginTransaction();
{
Node stefan = db.createLabeledNode( label(„Person“) );
stefan.setProperty( „name“, „Stefan“ );
Node chris = db.createNode( label(„Person“) );
chris.setProperty( „name“, „Chris“ );
stefan.createRelationshipTo( chris, withName(„FRIEND“) );
tx.success();
}
finally
{
tx.finish();
}
2.0
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Java Core API: Kanten traversieren
• GraphDatabaseService = new EmbeddedGraphDatabase( "var/graphDb" );
Transaction tx = gds.beginTransaction();
{
Node stefan = gds.findNodesByLabelAndProperty( label(„Person“), „Stefan“ );
for ( Relationship rel : stefan.getRelationships( withName(„FRIEND“) ) ) {
result.add( rel.getProperty(„name“) );
}
tx.success();
}
finally
{
tx.finish();
}
2.0
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
REST API
• Core API Operationen via REST / JSON
• Cypher-Anfragen via REST, in 2.0 auch Transaktionen
• Beispiel: Knoten anlegen
curl -XPOST http://localhost:7474/db/data/node -d ,{ „name“: „Stefan“ }‘
• Beispiel: Cypher ausführen
curl -XPOST http://localhost:7474/db/data/cypher -d „Cypher-Query“
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher
• Neo4j‘s
• Deklarative
• Graph
• Anfragesprache
• Wie SQL ... nur für Graphen!
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher: Basic Example
// get node with id 0
start a=node(0) return a
// traverse from node 1
start a=node(1) match (a)-->(b) return b
// return friends of friends
start a=node(1) match (a)--()--(c) return c
• Deklarative Anfragesprache für Graphdatenbanken mit „SQL-Klausel-Syntax“
• Visuelles Graph Pattern-Matching um zu beschreiben, was man benötigt
• Ergebnis in Tabellenform
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher: Friends of a friend that ...
// traverse to find results
start n=node:People(name = „Andreas“)
match (n)--(f)--(foaf) return foaf
name:Andreas
job: talking
name: Tobias
job: coding
knows
since: 2008
knows
since: 2006
name: Peter
job: building
name: Emil
job: plumber
knows
since: 1992
name: Stephen
job: DJ
knows
since: 2002
knows
since: 2006
name: Delia
job: barking
knows
since: 2002
knows
since: 1998
name: Tiberius
job: dancer
knows
since: 2000
name: Allison
job: plumberknows
since: 2002
knows
since: 1998
knows
since: 1996
n
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher: Filtern und Sortieren
// lookup all nodes as 'n', constrained to name 'Stefan'
start n=node(*) where n.name='Stefan' return n
// filter nodes where age is less than 30
start n=node(*) where n.age<30 return n
// filter and aggregation using a regular expression
start n=node(*) where n.name =~ “Mat.*“ return count(n)
// find nodes with a property and return first 3 found
start n=node(*) where has(n.name) return n limit 3
• Filtern mit Prädikaten in WHERE-Klausel
• Aggregation, Sortieren, Begrenzen
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher: Änderungen an der Datenbanke
// create node
create (a {name : 'Andres'})
// create relationship
create (a {name : 'Andres'})-[:knows]->(b {name: 'Stefan'})
// match and update
start n=node(*) where n.age = 34 set n.age = 35
// find node and delete it
start n=node(*) where n.name = 'Dr. Evil' delete n
• Hinzfügen von Knoten und Kanten
• Aktualisieren von Knoten und Kanten
• Löschen von Knoten und Kanten
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Cypher: Viel Mehr
• Shortest Path und Umgang mit Pfadmengen
• Funktionale Techniken: Flat, Map, etc.
• Optionale Muster
• Anfragen kombinieren
• Profiling
• ...
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Use-Cases
• Social Networks &
Recommendations
• Geospatial
• Infrastructure as a Service
• Business Intelligence
• Content Management
• Access Control
• Bioinformatics
• Genealogie
• Telco
• Finance
• ...
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Use Case: Social Collaboration
• Online Platform für globale
Kollaboration
• Datacenter pro Kontinent
• Hochverfürbar, weltweit
• <1s Antwortzeit für grosse, stark
vernetzte Datenmenge
Asia North America Europe
Asia North America Europe
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Use Case: Social Recommendation
• Social Network mit
35.000.000 Nutzern
• Recommendations
• Problem:
• MySQL didn‘t scale
• Batch job >1d, >2d, ...
• Ziel:
Up-to-date Recommendations
• Keine Batch-Jobs
• Lösung
• Real-Time Recommendations
• 8 Wochen
• Skaliert
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Configuration and Network Management
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Use-Case: Configuration and Network
Management
• Physikalisches und logisches Netzwerk modellieren
• Impaktanalyse
• Konfigurationsmanagement
• Network Inventory
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Geospatial
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Use-Case:
ACL from Hell
• Utility Company
• > 5.000.000 Nutzer
• Komplexe Regen
• Vorteile
• Flexible dynamisch erweiterbare
Architekur
• Geringe Kosten
• Hohe Performance
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Ausblick auf Neo4j 2.0
• Labels
• Unique Constraints
• Neues Index-Handling
• Cypher-Erweiterungen
• ...
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Learn More
http://stackoverflow.com/questions/tagged/neo4j
http://groups.google.com/group/neo4j
https://github.com/neo4j/neo4j/issues
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Learn More
http://neo4j.meetup.com/
http://www.neo4j.org/participate/
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Learn More
http://neo4j.org
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Vielen Dank
Fragen?
Freitag, 30. August 13
© All Rights Reserved 2013 | Neo Technology, Inc.
Graphs are everywhere
Freitag, 30. August 13

More Related Content

Viewers also liked

Music recommendations API with Neo4j
Music recommendations API with Neo4jMusic recommendations API with Neo4j
Music recommendations API with Neo4jBoris Guarisma
 
Graphs in the Real World
Graphs in the Real WorldGraphs in the Real World
Graphs in the Real WorldNeo4j
 
8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab8b. Column Oriented Databases Lab
8b. Column Oriented Databases LabFabio Fumarola
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases labFabio Fumarola
 
8. key value databases laboratory
8. key value databases laboratory 8. key value databases laboratory
8. key value databases laboratory Fabio Fumarola
 
Neo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> CypherNeo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> Cypherjexp
 
Neo4j Makes Graphs Easy- GraphDays
Neo4j Makes Graphs Easy- GraphDaysNeo4j Makes Graphs Easy- GraphDays
Neo4j Makes Graphs Easy- GraphDaysNeo4j
 
Introducing Neo4j 3.0
Introducing Neo4j 3.0Introducing Neo4j 3.0
Introducing Neo4j 3.0Neo4j
 
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介ippei_suzuki
 
グラフデータベース「Neo4j」の 導入の導入
グラフデータベース「Neo4j」の 導入の導入グラフデータベース「Neo4j」の 導入の導入
グラフデータベース「Neo4j」の 導入の導入Hisao Soyama
 
Non-Relational Databases & Key/Value Stores
Non-Relational Databases & Key/Value StoresNon-Relational Databases & Key/Value Stores
Non-Relational Databases & Key/Value StoresJoël Perras
 
Using Neo4j from Java
Using Neo4j from JavaUsing Neo4j from Java
Using Neo4j from JavaNeo4j
 
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」までNeo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」までKeiichiro Seida
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In DepthFabio Fumarola
 
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜Takahiro Inoue
 
Intro to Neo4j and Graph Databases
Intro to Neo4j and Graph DatabasesIntro to Neo4j and Graph Databases
Intro to Neo4j and Graph DatabasesNeo4j
 
Importing Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowImporting Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowNeo4j
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingWorking With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingNeo4j
 
Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesPeter Neubauer
 
Graph database Use Cases
Graph database Use CasesGraph database Use Cases
Graph database Use CasesMax De Marzi
 

Viewers also liked (20)

Music recommendations API with Neo4j
Music recommendations API with Neo4jMusic recommendations API with Neo4j
Music recommendations API with Neo4j
 
Graphs in the Real World
Graphs in the Real WorldGraphs in the Real World
Graphs in the Real World
 
8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 
8. key value databases laboratory
8. key value databases laboratory 8. key value databases laboratory
8. key value databases laboratory
 
Neo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> CypherNeo4j -[:LOVES]-> Cypher
Neo4j -[:LOVES]-> Cypher
 
Neo4j Makes Graphs Easy- GraphDays
Neo4j Makes Graphs Easy- GraphDaysNeo4j Makes Graphs Easy- GraphDays
Neo4j Makes Graphs Easy- GraphDays
 
Introducing Neo4j 3.0
Introducing Neo4j 3.0Introducing Neo4j 3.0
Introducing Neo4j 3.0
 
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介
グラフデータベース:Neo4j、そしてRDBからの移行手順の紹介
 
グラフデータベース「Neo4j」の 導入の導入
グラフデータベース「Neo4j」の 導入の導入グラフデータベース「Neo4j」の 導入の導入
グラフデータベース「Neo4j」の 導入の導入
 
Non-Relational Databases & Key/Value Stores
Non-Relational Databases & Key/Value StoresNon-Relational Databases & Key/Value Stores
Non-Relational Databases & Key/Value Stores
 
Using Neo4j from Java
Using Neo4j from JavaUsing Neo4j from Java
Using Neo4j from Java
 
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」までNeo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
 
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜
「GraphDB徹底入門」〜構造や仕組み理解から使いどころ・種々のGraphDBの比較まで幅広く〜
 
Intro to Neo4j and Graph Databases
Intro to Neo4j and Graph DatabasesIntro to Neo4j and Graph Databases
Intro to Neo4j and Graph Databases
 
Importing Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowImporting Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflow
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingWorking With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
 
Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examples
 
Graph database Use Cases
Graph database Use CasesGraph database Use Cases
Graph database Use Cases
 

More from Java Usergroup Berlin-Brandenburg

Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Java Usergroup Berlin-Brandenburg
 
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Java Usergroup Berlin-Brandenburg
 

More from Java Usergroup Berlin-Brandenburg (19)

Microbenchmarks - Wer nicht weiß, was er misst misst Mist
Microbenchmarks - Wer nicht weiß, was er misst misst MistMicrobenchmarks - Wer nicht weiß, was er misst misst Mist
Microbenchmarks - Wer nicht weiß, was er misst misst Mist
 
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
Collections.compare(() -> JDK; Apache; Eclipse, Guava...});
 
Built To Last - Nachhaltige Software-Entwicklung
Built To Last - Nachhaltige Software-EntwicklungBuilt To Last - Nachhaltige Software-Entwicklung
Built To Last - Nachhaltige Software-Entwicklung
 
Feature Toggles On Steroids
Feature Toggles On SteroidsFeature Toggles On Steroids
Feature Toggles On Steroids
 
Resilience mit Hystrix
Resilience mit HystrixResilience mit Hystrix
Resilience mit Hystrix
 
Analysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4jAnalysis of software systems using jQAssistant and Neo4j
Analysis of software systems using jQAssistant and Neo4j
 
Get Back in Control of your SQL
Get Back in Control of your SQLGet Back in Control of your SQL
Get Back in Control of your SQL
 
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
Die fabelhafte Welt Java(Script)-getriebener Enterprise-WebApps (mit Ext JS)
 
Selbstvorstellung Steria Mummert Consulting
Selbstvorstellung Steria Mummert ConsultingSelbstvorstellung Steria Mummert Consulting
Selbstvorstellung Steria Mummert Consulting
 
Jbosseapclustering 130605100557-phpapp02
Jbosseapclustering 130605100557-phpapp02Jbosseapclustering 130605100557-phpapp02
Jbosseapclustering 130605100557-phpapp02
 
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
Jbossas7alsplattformmodernerenterprise anwendungen-130604114410-phpapp02
 
How long can you afford to Stop The World?
How long can you afford to Stop The World?How long can you afford to Stop The World?
How long can you afford to Stop The World?
 
JavaOne Update zur Java Plattform
JavaOne Update zur Java PlattformJavaOne Update zur Java Plattform
JavaOne Update zur Java Plattform
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Restructuring
RestructuringRestructuring
Restructuring
 
Fighting Layout Bugs
Fighting Layout BugsFighting Layout Bugs
Fighting Layout Bugs
 
Die Java Plattform Strategie
Die Java Plattform StrategieDie Java Plattform Strategie
Die Java Plattform Strategie
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Continuous Delivery in der Praxis
Continuous Delivery in der PraxisContinuous Delivery in der Praxis
Continuous Delivery in der Praxis
 

Graphdatenbanken mit Neo4j

  • 1. © All Rights Reserved 2013 | Neo Technology, Inc. Graphdatenbanken mit Neo4j Modell - Einsatz - Abfrage mit Cypher - Use-Cases - 2.0 Stefan Plantikow Freitag, 30. August 13
  • 2. © All Rights Reserved 2013 | Neo Technology, Inc. Guten Tag • Entwickler bei neo technology • Kernel und Abfragesprache • Neo4j 1.9 • Neo4j 2.0-M04 @boggle github.com/boggle stefan.plantikow@neotechnology.com Freitag, 30. August 13
  • 3. © All Rights Reserved 2013 | Neo Technology, Inc. Trends • Big Data „data sets so large and complex that it becomes difficult to process using on-hand database management tools“ • Grösser • Vernetzter • Vielfältiger Freitag, 30. August 13
  • 4. © All Rights Reserved 2013 | Neo Technology, Inc. NoSQL Komplexität Grösse Key-Value-Store Gering Gross Column-Store Mittel Mittel bis gross Document-Store Mittel Mittel Graphdatenbank Sehr hoch Mittel Freitag, 30. August 13
  • 5. © All Rights Reserved 2013 | Neo Technology, Inc. NoSQLComplexity Column Family Size Key-Value Store Document Databases Graph Databases 90% of use cases RDBMS Freitag, 30. August 13
  • 6. © All Rights Reserved 2013 | Neo Technology, Inc. Graphs != Charts Graph DB Kenntnisse Kennen Graph DBs Kennen keine Graph DBs Charts != Graphs Freitag, 30. August 13
  • 7. © All Rights Reserved 2013 | Neo Technology, Inc. Gerichteter Graph me Freitag, 30. August 13
  • 8. © All Rights Reserved 2013 | Neo Technology, Inc. Beispielgraphen diamond butterfly bullstar franklin horton hall-jankorobertson Freitag, 30. August 13
  • 9. © All Rights Reserved 2013 | Neo Technology, Inc. Beispielgraphen Freitag, 30. August 13
  • 10. © All Rights Reserved 2013 | Neo Technology, Inc. Graphen • Knoten („Dinge“) • Kanten/Relationships („Beziehungen“, oft gerichtet) • Mathematik: Multigraphen, Hypergraphen, Probabilistische Graphen, ... • Graphdatenbanken: Property Graphs (Gerichteter Multigraph mit Properties) • Key-Value Properties: Name, Letzter Login, Anzahl Posts, ... • Label: Person, Artikel, Vorgang, ... • Indices: Exakt nach Namen, Volltext nach Beschreibung, ... 2.0 Freitag, 30. August 13
  • 11. © All Rights Reserved 2013 | Neo Technology, Inc. Property Graphs name: Stefan id: @gmail title: Cloud Atlas type: Book :ORDERED copies: 5 when: 2012 name: Chris id: @gmail :FRIEND since: 2013 title: Cloud Atlas type: Movie :BROWSED times: 100 Freitag, 30. August 13
  • 12. © All Rights Reserved 2013 | Neo Technology, Inc. name: Stefan id: @gmail title: Cloud Atlas type: Book :ORDERED copies: 5 when: 2012 name: Chris id: @gmail :FRIEND since: 2013 title: Cloud Atlas type: Movie :BROWSED times: 100 Labeled Property Graphs Customer Customer Article Article TopHit High Volume 2.0 Freitag, 30. August 13
  • 13. © All Rights Reserved 2013 | Neo Technology, Inc. Beispielanfrage • Für einen Nutzer mit dem Namen „Stefan“, finde alle Artikel die sich seine Freunde mindestens 4x angesehen haben und liefere sie nach Häufigkeit sortiert zurück. • Ausgehend von Knoten und Kanten im Graph Finde Muster im Graph und berechne daraus das Ergebnis Freitag, 30. August 13
  • 14. © All Rights Reserved 2013 | Neo Technology, Inc. Beispielanfrage • START n=node(*) MATCH (n {name: „Stefan“), MATCH (n)-[:FRIEND]->(f), (f)-[r:VIEWED]->(a) WHERE r.browsed >= 4 RETURN a ORDER BY r.browsed • Ausgehend von Knoten und Kanten im Graph Finde Muster im Graph und berechne daraus das Ergebnis Freitag, 30. August 13
  • 15. © All Rights Reserved 2013 | Neo Technology, Inc. Beispielanfrage: Indexe, Muster, Ergebnis • Wie kommt man „in den Graph“? • Knoten- bzw. Kanten-Id • Indexe: Exakt, Volltext, Geospatial, Custom • Muster • Einschränkungen an Knoten und Kanten und ihre Verbindungen • Ergebnis • Sortieren • Aggregieren • Filtern & Umwandeln Freitag, 30. August 13
  • 16. © All Rights Reserved 2013 | Neo Technology, Inc. Vorteile von Graphen • Natürliches und mächtiges Datenmodell • Schnelles, problemfreies Object Mapping • Strukturelle Abfragen sind einfach • Beziehungen sind Modellelement 1. Klasse (nicht: implizite Joins) • Erweiterbares einheitliches Modell für alle Daten • Neue Properties • Beziehungen zwischen vorher unverbundenen Daten • Erfordert Umdenken! Freitag, 30. August 13
  • 17. © All Rights Reserved 2013 | Neo Technology, Inc. Typische Anwendungen • Social Networks & Recommendations • Geospatial • Infrastructure as a Service • Business Intelligence • Content Management • Access Control • Bioinformatics • Genealogie • Telco • Finance • ... (Fast) Alles ;) aber insbesondere: Freitag, 30. August 13
  • 18. © All Rights Reserved 2013 | Neo Technology, Inc. Modellierung • Von der Domäne zum Graph • Von der (relationalen) Anwendung zum Graph • Vergleich relationales Modellieren mit Modellierung im Graph • How-to-Model Freitag, 30. August 13
  • 19. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling Am Anfang ist das Whiteboard Freitag, 30. August 13
  • 20. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling • Vom Use-Case zum Datenbankschema Freitag, 30. August 13
  • 21. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling (1) name: Adam image: lolcat1.gif name: Sarah :SHARES :FRIEND_OF :LIKES text: Funny! :COMMENTED:ABOUT Freitag, 30. August 13
  • 22. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling (2) name: Adam id: adam@ image: lolcat1.gif downloads: 5.000.000 name: Sarah :SHARES :FRIEND_OF since: 1995 :LIKES text: Funny! source: mobile :COMMENTED when: 2013:ABOUT Freitag, 30. August 13
  • 23. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling (3) name: Adam id: adam@ text: Look at this! on: Mar-2013 name: Sarah :SHARED :FRIEND_OF since: 1995 :LIKES text: Funny! source: mobile :COMMENTED when: 2013 :ABOUT image: lolcat1.gif downloads: 5.000.000 Freitag, 30. August 13
  • 24. © All Rights Reserved 2013 | Neo Technology, Inc. Whiteboard Modelling (4) name: Adam id: adam@ text: Look at this! on: Mar-2013 name: Sarah :SHARED :FRIEND_OF since: 1995 :LIKES text: Funny! source: mobile :COMMENTED when: 2013 :ABOUT image: lolcat1.gif downloads: 5.000.000 2.0 User User Post CommentPost FileResource Freitag, 30. August 13
  • 25. © All Rights Reserved 2013 | Neo Technology, Inc. Graphen aus Relationen (1) Customers AccountsCustomer_Accounts 143 Alice 326 $100 725 $632 981 $212 143 981 143 725 143 326 Freitag, 30. August 13
  • 26. © All Rights Reserved 2013 | Neo Technology, Inc. Graphen aus Relationen (2) Alice $100 $632 $212 143 326 725 981 143 981 143 725 143 326 Freitag, 30. August 13
  • 27. © All Rights Reserved 2013 | Neo Technology, Inc. Graphen aus Relationen (3) name: Alice bal: $100 bal: $212 Nodes Relationships owns owns owns Freitag, 30. August 13
  • 28. © All Rights Reserved 2013 | Neo Technology, Inc. What language do they speak here? Language Country Freitag, 30. August 13
  • 29. © All Rights Reserved 2013 | Neo Technology, Inc. What language do they speak here? Language Country Freitag, 30. August 13
  • 30. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Tables (1) language_code language_name word_count Language country_code country_name flag_uri language_code Country Freitag, 30. August 13
  • 31. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Tables (2) language_code language_name word_count country_code Language country_code country_name flag_uri Country Freitag, 30. August 13
  • 32. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Tables (3) language_code language_name word_count Language country_code country_name flag_uri Country language_code country_code LanguageCountry Freitag, 30. August 13
  • 33. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Tables (4) language_code language_name word_count Language country_code country_name flag_uri Country language_code country_code primary LanguageCountry Freitag, 30. August 13
  • 34. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Graphs (1) name word_count Language name flag_uri Country IS_SPOKEN_IN Freitag, 30. August 13
  • 35. © All Rights Reserved 2013 | Neo Technology, Inc. Languages in Graphs (2) name word_count Language name flag_uri Country IS_SPOKEN_IN as_primary Freitag, 30. August 13
  • 36. © All Rights Reserved 2013 | Neo Technology, Inc. Unterschied: Languages in Tabellen vs. Graphs language_code language_name word_count Language country_code country_name flag_uri Country language_code country_code primary LanguageCountry IS_SPOKEN_IN Freitag, 30. August 13
  • 37. © All Rights Reserved 2013 | Neo Technology, Inc. How To Model • Normalisierung: Erst in einem Knoten sammeln - dann Aufteilen • ggf. Kanten einfügen um Relevantes zu verbinden • ggf. Properties in Kanten wandeln und umgekehrt • Unverbundene Knoten vermeiden • Zusätzliche Zugriffspfade anlegen, z.B. • zeitlich sortierte Linked List für Posts • „Abkürzungen“ Freitag, 30. August 13
  • 38. © All Rights Reserved 2013 | Neo Technology, Inc. Graphdatenbanken • NoSQL Datenbank • Speichert Property Graph Modell • zusätzliche Indexe • ggf. Label • Performance Definition: Bei steigender Knotenanzahl selber Aufwand für einen „Schritt“ im Graphen (in-memory) Freitag, 30. August 13
  • 39. © All Rights Reserved 2013 | Neo Technology, Inc. Graphdatenbanken • Performance Definition: Bei steigender Knotenanzahl selber Aufwand für einen „Schritt“ im Graphen (in-memory) • Social Graph mit 50 „Freunden“ pro Nutzer im Durchschnitte • Suche nach Freunden 4. Grades nach Datenbank-Warmup DB # Nutzer Zeit Relational 1.000 2000 ms Neo4j 1.000 2 ms Neo4j 1.000.000 2 ms Freitag, 30. August 13
  • 40. © All Rights Reserved 2013 | Neo Technology, Inc. Neo4j • Dual-Licensed: Open Source (AGPL) / Kommerziell • Transaktional (ACID) • Read-Committed (Serializable durch explizites Locking) • Server mit Web-UI • High Availability (Online Backup, Replikation) • Tooling: Shell, Backup, ... • Umfangreiche Community & Kommerzieller Support Freitag, 30. August 13
  • 41. © All Rights Reserved 2013 | Neo Technology, Inc. Neo4j Browser Nach Installation: http://localhost:7474 Freitag, 30. August 13
  • 42. © All Rights Reserved 2013 | Neo Technology, Inc. Neo4j Console Freitag, 30. August 13
  • 43. © All Rights Reserved 2013 | Neo Technology, Inc. Online Demo: console.neo4j.org Ausprobieren: start  n=node(*)  match  n-­‐[r:LOVES]-­‐>m  return  n,  type(r),  m (rote  Knoten  sind  Ergebnisknoten) Freitag, 30. August 13
  • 44. © All Rights Reserved 2013 | Neo Technology, Inc. Neo4j • Dual-Licensed: Open Source (AGPL) / Kommerziell • Transaktional (ACID) • Read-Committed (Serializable durch explizites Locking) • Server mit Web-UI • High Availability • Tooling: Shell, Backup, Monitoring (JMX), ... Freitag, 30. August 13
  • 45. © All Rights Reserved 2013 | Neo Technology, Inc. Neo4j Implementation • Kernel: Java Web-UI: Javascript • kaum Dependencies • kernel.jar: 2MB • DirectByteBuffer • GC-resistent custom caches • Anfragesprache Cypher: Scala 2.10 • Runtime mit Kernel integriert Freitag, 30. August 13
  • 46. © All Rights Reserved 2013 | Neo Technology, Inc. Einsatz • Anfragesprache Cypher • Embedded Database: Java Core API • Eingebettet in Application Container oder eigene Middleware • Server: REST API • Custom Server Extensions Freitag, 30. August 13
  • 47. © All Rights Reserved 2013 | Neo Technology, Inc. Schnittstellen • Neo4j • Java Core API • REST API • Graph Frameworks • Spring Data Graph • Blueprints Neo4j • Third Party Language Drivers • JDBCS • Ruby • Javascript • .NET • Clojure • Python... Freitag, 30. August 13
  • 48. © All Rights Reserved 2013 | Neo Technology, Inc. Java Core API Operationen • Transaktionen • Knoten und Kanten anlegen • Index Lookup • Traversierung • GlobalGraphOperations (alle Knoten etc.) • Zusätzliche APIs: A*, Custom Traversers, Batch Insertion, Transaction Handler Freitag, 30. August 13
  • 49. © All Rights Reserved 2013 | Neo Technology, Inc. Java Core API: Knoten und Kanten einfügen • GraphDatabaseService = new EmbeddedGraphDatabase( "var/graphDb" ); Transaction tx = gds.beginTransaction(); { Node stefan = db.createLabeledNode( label(„Person“) ); stefan.setProperty( „name“, „Stefan“ ); Node chris = db.createNode( label(„Person“) ); chris.setProperty( „name“, „Chris“ ); stefan.createRelationshipTo( chris, withName(„FRIEND“) ); tx.success(); } finally { tx.finish(); } 2.0 Freitag, 30. August 13
  • 50. © All Rights Reserved 2013 | Neo Technology, Inc. Java Core API: Kanten traversieren • GraphDatabaseService = new EmbeddedGraphDatabase( "var/graphDb" ); Transaction tx = gds.beginTransaction(); { Node stefan = gds.findNodesByLabelAndProperty( label(„Person“), „Stefan“ ); for ( Relationship rel : stefan.getRelationships( withName(„FRIEND“) ) ) { result.add( rel.getProperty(„name“) ); } tx.success(); } finally { tx.finish(); } 2.0 Freitag, 30. August 13
  • 51. © All Rights Reserved 2013 | Neo Technology, Inc. REST API • Core API Operationen via REST / JSON • Cypher-Anfragen via REST, in 2.0 auch Transaktionen • Beispiel: Knoten anlegen curl -XPOST http://localhost:7474/db/data/node -d ,{ „name“: „Stefan“ }‘ • Beispiel: Cypher ausführen curl -XPOST http://localhost:7474/db/data/cypher -d „Cypher-Query“ Freitag, 30. August 13
  • 52. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher • Neo4j‘s • Deklarative • Graph • Anfragesprache • Wie SQL ... nur für Graphen! Freitag, 30. August 13
  • 53. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher: Basic Example // get node with id 0 start a=node(0) return a // traverse from node 1 start a=node(1) match (a)-->(b) return b // return friends of friends start a=node(1) match (a)--()--(c) return c • Deklarative Anfragesprache für Graphdatenbanken mit „SQL-Klausel-Syntax“ • Visuelles Graph Pattern-Matching um zu beschreiben, was man benötigt • Ergebnis in Tabellenform Freitag, 30. August 13
  • 54. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher: Friends of a friend that ... // traverse to find results start n=node:People(name = „Andreas“) match (n)--(f)--(foaf) return foaf name:Andreas job: talking name: Tobias job: coding knows since: 2008 knows since: 2006 name: Peter job: building name: Emil job: plumber knows since: 1992 name: Stephen job: DJ knows since: 2002 knows since: 2006 name: Delia job: barking knows since: 2002 knows since: 1998 name: Tiberius job: dancer knows since: 2000 name: Allison job: plumberknows since: 2002 knows since: 1998 knows since: 1996 n Freitag, 30. August 13
  • 55. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher: Filtern und Sortieren // lookup all nodes as 'n', constrained to name 'Stefan' start n=node(*) where n.name='Stefan' return n // filter nodes where age is less than 30 start n=node(*) where n.age<30 return n // filter and aggregation using a regular expression start n=node(*) where n.name =~ “Mat.*“ return count(n) // find nodes with a property and return first 3 found start n=node(*) where has(n.name) return n limit 3 • Filtern mit Prädikaten in WHERE-Klausel • Aggregation, Sortieren, Begrenzen Freitag, 30. August 13
  • 56. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher: Änderungen an der Datenbanke // create node create (a {name : 'Andres'}) // create relationship create (a {name : 'Andres'})-[:knows]->(b {name: 'Stefan'}) // match and update start n=node(*) where n.age = 34 set n.age = 35 // find node and delete it start n=node(*) where n.name = 'Dr. Evil' delete n • Hinzfügen von Knoten und Kanten • Aktualisieren von Knoten und Kanten • Löschen von Knoten und Kanten Freitag, 30. August 13
  • 57. © All Rights Reserved 2013 | Neo Technology, Inc. Cypher: Viel Mehr • Shortest Path und Umgang mit Pfadmengen • Funktionale Techniken: Flat, Map, etc. • Optionale Muster • Anfragen kombinieren • Profiling • ... Freitag, 30. August 13
  • 58. © All Rights Reserved 2013 | Neo Technology, Inc. Use-Cases • Social Networks & Recommendations • Geospatial • Infrastructure as a Service • Business Intelligence • Content Management • Access Control • Bioinformatics • Genealogie • Telco • Finance • ... Freitag, 30. August 13
  • 59. © All Rights Reserved 2013 | Neo Technology, Inc. Use Case: Social Collaboration • Online Platform für globale Kollaboration • Datacenter pro Kontinent • Hochverfürbar, weltweit • <1s Antwortzeit für grosse, stark vernetzte Datenmenge Asia North America Europe Asia North America Europe Freitag, 30. August 13
  • 60. © All Rights Reserved 2013 | Neo Technology, Inc. Use Case: Social Recommendation • Social Network mit 35.000.000 Nutzern • Recommendations • Problem: • MySQL didn‘t scale • Batch job >1d, >2d, ... • Ziel: Up-to-date Recommendations • Keine Batch-Jobs • Lösung • Real-Time Recommendations • 8 Wochen • Skaliert Freitag, 30. August 13
  • 61. © All Rights Reserved 2013 | Neo Technology, Inc. Configuration and Network Management Freitag, 30. August 13
  • 62. © All Rights Reserved 2013 | Neo Technology, Inc. Use-Case: Configuration and Network Management • Physikalisches und logisches Netzwerk modellieren • Impaktanalyse • Konfigurationsmanagement • Network Inventory Freitag, 30. August 13
  • 63. © All Rights Reserved 2013 | Neo Technology, Inc. Geospatial Freitag, 30. August 13
  • 64. © All Rights Reserved 2013 | Neo Technology, Inc. Use-Case: ACL from Hell • Utility Company • > 5.000.000 Nutzer • Komplexe Regen • Vorteile • Flexible dynamisch erweiterbare Architekur • Geringe Kosten • Hohe Performance Freitag, 30. August 13
  • 65. © All Rights Reserved 2013 | Neo Technology, Inc. Ausblick auf Neo4j 2.0 • Labels • Unique Constraints • Neues Index-Handling • Cypher-Erweiterungen • ... Freitag, 30. August 13
  • 66. © All Rights Reserved 2013 | Neo Technology, Inc. Learn More http://stackoverflow.com/questions/tagged/neo4j http://groups.google.com/group/neo4j https://github.com/neo4j/neo4j/issues Freitag, 30. August 13
  • 67. © All Rights Reserved 2013 | Neo Technology, Inc. Learn More http://neo4j.meetup.com/ http://www.neo4j.org/participate/ Freitag, 30. August 13
  • 68. © All Rights Reserved 2013 | Neo Technology, Inc. Learn More http://neo4j.org Freitag, 30. August 13
  • 69. © All Rights Reserved 2013 | Neo Technology, Inc. Vielen Dank Fragen? Freitag, 30. August 13
  • 70. © All Rights Reserved 2013 | Neo Technology, Inc. Graphs are everywhere Freitag, 30. August 13