SlideShare a Scribd company logo
1 of 39
Download to read offline
En lynintroduksjon til
grafdatabaser og Neo4j
Aleksander M. Stensby
aleksander (dot) stensby (at) gmail (dot) com
Agenda
• Intro til grafdatabaser og modellering
• Intro til neo4j og Cypher
• (Intro til SpringData Neo4j)
... på 15 minutter!
Relasjondatabaser suger...
...på relasjoner
Relasjondatabaser er fantastisk på
aggregering av data, mapping av
skjemaer og tabell data!
MEN
vi har en tendens til å tvinge
_alle_
problemstillinger inn i
relasjondatabasene våre!
Join-hell..
Rekursjon...
Null-sjekking...
NoSQLStørrelse
Kompleksitet
Grafer
Dokument
BigTable
KV
NoSQLStørrelse
Kompleksitet
Grafer
Dokument
BigTable
KV
90%
Milliarder av noder og relasjoner
Venner av venner...
Person
ID
Navn
Venner
PersonID
VennID
«Aleks» sine venners venner?
SELECT p1.Person AS PERSON, p2.Person AS VENN_AV_VENN
FROM Venner v1 JOIN Person p1
ON v1.PersonID = p1.ID
JOIN Venner v2
ON v2.VennID = v1.VennID
JOIN Person p2
ON v2.VennID = p2. ID
WHERE p1.Navn = 'Aleks‘ AND v2.VennID <> p1.ID
Kilde: Neo4j in Action
1,000,000 personer
Dybde RDBMS Neo4j Antall rader
2 0.016 0.01 ~ 2500
3 30.267 0.168 ~ 110,000
4 1543.505 1.359 ~ 600,000
5 DNF 2.132 ~ 800,000
En grafdatabase...
• benytter grafstrukturer med
– Noder
– Relasjoner
– Attributter
• til å lagre informasjon!
• Ypperlig til relasjoner – men ikke best på
aggregering av data
En graf lagrer data i noder
ALEKS RAYMOND
Relasjoner knytter noder sammen
FRIENDS_WITH
ALEKS RAYMOND
Noder har attributter
ALEKS RAYMOND
Age: 29
First Name: Aleksander
Last Name: Stensby
Age: 31
First Name: Raymond
Last Name: Koteng
FRIENDS_WITH
Relasjoner kan også ha attributter
ALEKS RAYMOND
Age: 29
First Name: Aleksander
Last Name: Stensby
Age: 31
First Name: Raymond
Last Name: Koteng
FRIENDS_WITH
Since: 01.01.2004
Relasjoner kan gå flere veier
ALEKS RAYMOND
Age: 29
First Name: Aleksander
Last Name: Stensby
Age: 31
First Name: Raymond
Last Name: Koteng
FRIENDS_WITH
Since: 01.01.2004
FRIENDS_WITH
Since: 01.01.2004
ALEKS RAYMOND
Age: 29
First Name: Aleksander
Last Name: Stensby
Age: 31
First Name: Raymond
Last Name: Koteng
FRIENDS_WITH
Since: 01.01.2004
ALEKS RAYMOND
Age: 29
First Name: Aleksander
Last Name: Stensby
Type: Person
Age: 31
First Name: Raymond
Last Name: Koteng
Type: Person
FRIENDS_WITH
Since: 01.01.2004
forskjellige typer av noder
Person Person
Sport
Programmeringspråk
Drikke
Person
Neo4j – [ER_EN] -> Property Graph
Cypher
"Make the simple things simple, and the complex things possible"
Intro til Cypher
• START
• MATCH
• WHERE
• RETURN
• CREATE
• DELETE
• SET
• FOREACH
• WITH
Beskriv hva du ønsker å hente ut med
PATTERNS
(a)-[r]->(b)
(Aleks) – [FRIENDS_WITH] -> (Raymond)
MATCH
MATCH (movie:Movie)
RETURN movie
WHERE
MATCH movie
WHERE move.title = ‘Blade Runner'
RETURN movie
Venner...
MATCH (aleks)-[:KNOWS]->(friend)
WHERE aleks.firstName= 'Aleks'
RETURN friend.firstName
Venners venner...
MATCH (aleks)-[:KNOWS]->(friend)-[:KNOWS]->(friend_of_friend)
WHERE aleks.firstName= 'Aleks'
RETURN friend_of_friend.firstName
Venners venner...
MATCH (aleks)-[:KNOWS*2]->(friend_of_friend)
WHERE aleks.firstName= 'Aleks'
RETURN friend_of_friend.firstName
Venners venner...
MATCH (aleks)-[:KNOWS*2..2]->(friend_of_friend)
WHERE aleks.firstName= 'Aleks'
AND NOT (aleks)-[:KNOWS]->(friend_of_friend)
RETURN friend_of_friend.firstName
på 1-2-3
DEMO
Og mye mye mer...
• Traversals navigerer grafen
• Traversals identifiserer paths
• Paths ordner noder
• Cypher parametere
• Indexes
• Neo4j embedded, Neo4j REST
• Neo4j 2.x – Labels og automatiske indekser
• Gremlin (procedural) – Cypher (declarative)
• Enterprise (multi-instance cluster, online backup)
• Neo4j Spatial
Lessons Learned
• Vær forsiktig med versjoner og oppgraderinger…
– Neo 1.9.x -> Neo 2.x kan by på mange problemer
– Spring Data Neo4j != Neo4j
• Noder er “first-class” citizens I grafen
– Hyperedges støttes ikke -> kan bruke “event nodes”
• Dyrt å aggregere - caching av stats på noder!
• Unike og ekspressive relasjonstyper
Lynintroduksjon til grafdatabaser og Neo4j

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Lynintroduksjon til grafdatabaser og Neo4j