Neo4j makes Graphs Easy
Overview
Step 1: Data and Relationships
#1
Step 2: Loading your Data into Neo4j
#2
Step 3: Querying your Data
#3a
#3b
Data and Relationships
Find all the code at
https://github.com/kvangundy/GraphDays
NorthWind
What if we used SQL?
Neo4j Makes Graphs Easy
Let’s make a Graph
Building Relationships in Graphs
-name
-employeeID
-orderNum
-shippedOn
SOLD
PRODUCT
PART_OF
SUPPLIES
Modeling it as a Graph
What’s Next?
Step 2: Loading your Data into Neo4j
#2
#3
Querying your Data
Cypher Query Language
Basic Query: Who do people report to?
Basic Query: Who do people report to?
MATCH
(e:Employee)<-[:REPORTS_TO]-(sub:Employee)
RETURN
e.employeeID AS managerID,
e.firstName AS managerName,
sub.employeeID AS employeeID,
sub.firstName AS employeeName;
Basic Query: Who do people report to?
Querying your Data
Query Browser
To The Browser!
Holy nodes
Batman!
Querying your Data
REST Drivers
REST Drivers
Java
.NET
JavaScript
Python
Ruby
PHP
ANYWHERE…
Python Code
Loading your Data
C S V
CSV Files for Northwind Data
CSV Files for Northwind Data
Step-by-step Creating the Graph
1.Create the core data
2.Create indexes on the data for performance
3.Create the relationships
LOADing the Data
//Create customers
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/customers.csv" AS row
CREATE (:Customer {companyName: row.CompanyName, customerID:
row.CustomerID, fax: row.Fax, phone: row.Phone});
//Create products
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row
CREATE (:Product {productName: row.ProductName, productID: row.ProductID,
unitPrice: toFloat(row.UnitPrice)});
LOADing the Data
// Create suppliers
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/suppliers.csv" AS row
CREATE (:Supplier {companyName: row.CompanyName, supplierID:
row.SupplierID});
// Create employees
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row
CREATE (:Employee {employeeID:row.EmployeeID, firstName: row.FirstName,
lastName: row.LastName, title: row.Title});
LOADing the Data
// Create categories
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/categories.csv" AS row
CREATE (:Category {categoryID: row.CategoryID, categoryName:
row.CategoryName, description: row.Description});
// Create orders
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row
MERGE (order:Order {orderID: row.OrderID}) ON CREATE SET order.shipName =
row.ShipName;
Creating the Indexes
CREATE INDEX ON :Product(productID);
CREATE INDEX ON :Product(productName);
CREATE INDEX ON :Category(categoryID);
CREATE INDEX ON :Employee(employeeID);
CREATE INDEX ON :Supplier(supplierID);
CREATE INDEX ON :Customer(customerID);
CREATE INDEX ON :Customer(customerName);
Creating the Relationships
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row
MATCH (order:Order {orderID: row.OrderID})
MATCH (customer:Customer {customerID: row.CustomerID})
MERGE (customer)-[:PURCHASED]->(order);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row
MATCH (product:Product {productID: row.ProductID})
MATCH (supplier:Supplier {supplierID: row.SupplierID})
MERGE (supplier)-[:SUPPLIES]->(product);
Creating the Relationships
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row
MATCH (product:Product {productID: row.ProductID})
MATCH (category:Category {categoryID: row.CategoryID})
MERGE (product)-[:PART_OF]->(category);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row
MATCH (employee:Employee {employeeID: row.EmployeeID})
MATCH (manager:Employee {employeeID: row.ReportsTo})
MERGE (employee)-[:REPORTS_TO]->(manager);
Creating the Relationships
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row
MATCH (order:Order {orderID: row.OrderID})
MATCH (product:Product {productID: row.ProductID})
MERGE (order)-[relation:PRODUCT]->(product)
ON CREATE SET relation.unitPrice = toFloat(row.UnitPrice), relation.quantit
= toFloat(row.Quantity);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-
contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row
MATCH (order:Order {orderID: row.OrderID})
MATCH (employee:Employee {employeeID: row.EmployeeID})
MERGE (employee)-[:SOLD]->(order);
Recap
What we talked about Today
#1 #2
#3a
#3b
Questions?
Go Forth and Be Graphy.

More Related Content

PDF
Building a production-ready, graph-based enterprise application in the cloud
PDF
Day 4 - Advance Python - Ground Gurus
PPTX
Search Queries Explained – A Deep Dive into Query Rules, Query Variables and ...
PPTX
Scrapy-101
PDF
Using script db as a deaddrop to pass data between GAS, JS and Excel
PPTX
Kql and the content search web part
PPTX
KEY
Google App Engine with Gaelyk
Building a production-ready, graph-based enterprise application in the cloud
Day 4 - Advance Python - Ground Gurus
Search Queries Explained – A Deep Dive into Query Rules, Query Variables and ...
Scrapy-101
Using script db as a deaddrop to pass data between GAS, JS and Excel
Kql and the content search web part
Google App Engine with Gaelyk

What's hot (11)

PPSX
Azure DocumentDB
PDF
Web_Crawler
PDF
Easing offline web application development with GWT
ODP
Introducing CouchDB
ODP
Building a Cloud API Server using Play(SCALA) & Riak
PPTX
How to automate all your SEO projects
KEY
Routes Controllers
PDF
React for Beginners
PPTX
Google Apps Script the Authentic{ated} Mobile Playground
PDF
Riak Intro at Munich Node.js
Azure DocumentDB
Web_Crawler
Easing offline web application development with GWT
Introducing CouchDB
Building a Cloud API Server using Play(SCALA) & Riak
How to automate all your SEO projects
Routes Controllers
React for Beginners
Google Apps Script the Authentic{ated} Mobile Playground
Riak Intro at Munich Node.js
Ad

Viewers also liked (20)

PDF
Graph Your Business - GraphDay JimWebber
PDF
Graph your business
PDF
Transparency One : La (re)découverte de la chaîne d'approvisionnement
PDF
Graph all the things
PDF
GraphConnect 2014 SF: The Business Graph
PDF
Neo4j Makes Graphs Easy? - GraphDay AmandaLaucher
PDF
GraphConnect 2014 SF: Betting the Company on a Graph Database - Part 2
PDF
Graph Search and Discovery for your Dark Data
PPTX
GraphTalk Frankfurt - Master Data Management bei der Bayerischen Versicherung
PPTX
GraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration Patterns
PDF
Metadata and Access Control
PDF
GraphDay Noble/Coolio
PDF
Meetup Analytics with R and Neo4j
PPTX
Graphs fun vjug2
PDF
GraphTalk - Semantische Netze mit structr
PPTX
GraphTalk Frankfurt - Einführung in Graphdatenbanken
PPTX
Graph all the things - PRathle
PPTX
GraphTalks - Einführung
PPTX
GraphTalk - Semantisches PDM bei Schleich
PDF
RDBMS to Graphs
Graph Your Business - GraphDay JimWebber
Graph your business
Transparency One : La (re)découverte de la chaîne d'approvisionnement
Graph all the things
GraphConnect 2014 SF: The Business Graph
Neo4j Makes Graphs Easy? - GraphDay AmandaLaucher
GraphConnect 2014 SF: Betting the Company on a Graph Database - Part 2
Graph Search and Discovery for your Dark Data
GraphTalk Frankfurt - Master Data Management bei der Bayerischen Versicherung
GraphConnect 2014 SF: Neo4j at Scale using Enterprise Integration Patterns
Metadata and Access Control
GraphDay Noble/Coolio
Meetup Analytics with R and Neo4j
Graphs fun vjug2
GraphTalk - Semantische Netze mit structr
GraphTalk Frankfurt - Einführung in Graphdatenbanken
Graph all the things - PRathle
GraphTalks - Einführung
GraphTalk - Semantisches PDM bei Schleich
RDBMS to Graphs
Ad

Similar to Neo4j Makes Graphs Easy (20)

PDF
Neo4j (Part 1)
PDF
New opportunities for connected data
PPTX
Neo4j Training Introduction
PDF
Neo4j Introduction (for Techies)
PDF
Spring Data Neo4j: Graph Power Your Enterprise Apps
PDF
Tackling Complex Data with Neo4j by Ian Robinson
PDF
Modelling Data in Neo4j (plus a few tips)
PDF
managing big data
PPTX
Introduction: Relational to Graphs
PDF
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
PDF
Interpreting Relational Schema to Graphs
PPTX
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
PDF
Neo4j Database and Graph Platform Overview
PPTX
A whirlwind tour of graph databases
PDF
Training Series - Intro to Neo4j
PDF
Modelling Data in Neo4j (plus a few tips)
PDF
Introduction to Graphs with Neo4j
PDF
Neo4j 4 Overview
PDF
Neo4j: The path to success with Graph Database and Graph Data Science
PDF
RadioBOSS Advanced 7.0.8 Free Download
Neo4j (Part 1)
New opportunities for connected data
Neo4j Training Introduction
Neo4j Introduction (for Techies)
Spring Data Neo4j: Graph Power Your Enterprise Apps
Tackling Complex Data with Neo4j by Ian Robinson
Modelling Data in Neo4j (plus a few tips)
managing big data
Introduction: Relational to Graphs
Introduction to Graph databases and Neo4j (by Stefan Armbruster)
Interpreting Relational Schema to Graphs
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
Neo4j Database and Graph Platform Overview
A whirlwind tour of graph databases
Training Series - Intro to Neo4j
Modelling Data in Neo4j (plus a few tips)
Introduction to Graphs with Neo4j
Neo4j 4 Overview
Neo4j: The path to success with Graph Database and Graph Data Science
RadioBOSS Advanced 7.0.8 Free Download

More from Neo4j (20)

PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
PDF
Jin Foo - Prospa GraphSummit Sydney Presentation.pdf
PDF
GraphSummit Singapore Master Deck - May 20, 2025
PPTX
Graphs & GraphRAG - Essential Ingredients for GenAI
PPTX
Neo4j Knowledge for Customer Experience.pptx
PPTX
GraphTalk New Zealand - The Art of The Possible.pptx
PDF
Neo4j: The Art of the Possible with Graph
PDF
Smarter Knowledge Graphs For Public Sector
PDF
GraphRAG and Knowledge Graphs Exploring AI's Future
PDF
Matinée GenAI & GraphRAG Paris - Décembre 24
PDF
ANZ Presentation: GraphSummit Melbourne 2024
PDF
Google Cloud Presentation GraphSummit Melbourne 2024: Building Generative AI ...
PDF
Telstra Presentation GraphSummit Melbourne: Optimising Business Outcomes with...
PDF
Hands-On GraphRAG Workshop: GraphSummit Melbourne 2024
PDF
Démonstration Digital Twin Building Wire Management
PDF
Swiss Life - Les graphes au service de la détection de fraude dans le domaine...
PDF
Démonstration Supply Chain - GraphTalk Paris
PDF
The Art of Possible - GraphTalk Paris Opening Session
PPTX
How Siemens bolstered supply chain resilience with graph-powered AI insights ...
PDF
Knowledge Graphs for AI-Ready Data and Enterprise Deployment - Gartner IT Sym...
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Jin Foo - Prospa GraphSummit Sydney Presentation.pdf
GraphSummit Singapore Master Deck - May 20, 2025
Graphs & GraphRAG - Essential Ingredients for GenAI
Neo4j Knowledge for Customer Experience.pptx
GraphTalk New Zealand - The Art of The Possible.pptx
Neo4j: The Art of the Possible with Graph
Smarter Knowledge Graphs For Public Sector
GraphRAG and Knowledge Graphs Exploring AI's Future
Matinée GenAI & GraphRAG Paris - Décembre 24
ANZ Presentation: GraphSummit Melbourne 2024
Google Cloud Presentation GraphSummit Melbourne 2024: Building Generative AI ...
Telstra Presentation GraphSummit Melbourne: Optimising Business Outcomes with...
Hands-On GraphRAG Workshop: GraphSummit Melbourne 2024
Démonstration Digital Twin Building Wire Management
Swiss Life - Les graphes au service de la détection de fraude dans le domaine...
Démonstration Supply Chain - GraphTalk Paris
The Art of Possible - GraphTalk Paris Opening Session
How Siemens bolstered supply chain resilience with graph-powered AI insights ...
Knowledge Graphs for AI-Ready Data and Enterprise Deployment - Gartner IT Sym...

Recently uploaded (20)

PDF
STKI Israel Market Study 2025 version august
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Modernising the Digital Integration Hub
PDF
sustainability-14-14877-v2.pddhzftheheeeee
DOCX
search engine optimization ppt fir known well about this
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
August Patch Tuesday
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Five Habits of High-Impact Board Members
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Developing a website for English-speaking practice to English as a foreign la...
STKI Israel Market Study 2025 version august
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hindi spoken digit analysis for native and non-native speakers
Modernising the Digital Integration Hub
sustainability-14-14877-v2.pddhzftheheeeee
search engine optimization ppt fir known well about this
WOOl fibre morphology and structure.pdf for textiles
Benefits of Physical activity for teenagers.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Taming the Chaos: How to Turn Unstructured Data into Decisions
A review of recent deep learning applications in wood surface defect identifi...
Zenith AI: Advanced Artificial Intelligence
August Patch Tuesday
Module 1.ppt Iot fundamentals and Architecture
Enhancing emotion recognition model for a student engagement use case through...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Five Habits of High-Impact Board Members
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Developing a website for English-speaking practice to English as a foreign la...

Neo4j Makes Graphs Easy

  • 3. Step 1: Data and Relationships #1
  • 4. Step 2: Loading your Data into Neo4j #2
  • 5. Step 3: Querying your Data #3a #3b
  • 6. Data and Relationships Find all the code at https://github.com/kvangundy/GraphDays NorthWind
  • 7. What if we used SQL?
  • 10. Building Relationships in Graphs -name -employeeID -orderNum -shippedOn
  • 12. Modeling it as a Graph
  • 14. Step 2: Loading your Data into Neo4j #2 #3
  • 15. Querying your Data Cypher Query Language
  • 16. Basic Query: Who do people report to?
  • 17. Basic Query: Who do people report to? MATCH (e:Employee)<-[:REPORTS_TO]-(sub:Employee) RETURN e.employeeID AS managerID, e.firstName AS managerName, sub.employeeID AS employeeID, sub.firstName AS employeeName;
  • 18. Basic Query: Who do people report to?
  • 20. To The Browser! Holy nodes Batman!
  • 25. C S V
  • 26. CSV Files for Northwind Data
  • 27. CSV Files for Northwind Data
  • 28. Step-by-step Creating the Graph 1.Create the core data 2.Create indexes on the data for performance 3.Create the relationships
  • 29. LOADing the Data //Create customers USING PERIODIC COMMIT 1000 LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/customers.csv" AS row CREATE (:Customer {companyName: row.CompanyName, customerID: row.CustomerID, fax: row.Fax, phone: row.Phone}); //Create products USING PERIODIC COMMIT 1000 LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row CREATE (:Product {productName: row.ProductName, productID: row.ProductID, unitPrice: toFloat(row.UnitPrice)});
  • 30. LOADing the Data // Create suppliers USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/suppliers.csv" AS row CREATE (:Supplier {companyName: row.CompanyName, supplierID: row.SupplierID}); // Create employees USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row CREATE (:Employee {employeeID:row.EmployeeID, firstName: row.FirstName, lastName: row.LastName, title: row.Title});
  • 31. LOADing the Data // Create categories USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/categories.csv" AS row CREATE (:Category {categoryID: row.CategoryID, categoryName: row.CategoryName, description: row.Description}); // Create orders USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row MERGE (order:Order {orderID: row.OrderID}) ON CREATE SET order.shipName = row.ShipName;
  • 32. Creating the Indexes CREATE INDEX ON :Product(productID); CREATE INDEX ON :Product(productName); CREATE INDEX ON :Category(categoryID); CREATE INDEX ON :Employee(employeeID); CREATE INDEX ON :Supplier(supplierID); CREATE INDEX ON :Customer(customerID); CREATE INDEX ON :Customer(customerName);
  • 33. Creating the Relationships USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row MATCH (order:Order {orderID: row.OrderID}) MATCH (customer:Customer {customerID: row.CustomerID}) MERGE (customer)-[:PURCHASED]->(order); USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row MATCH (product:Product {productID: row.ProductID}) MATCH (supplier:Supplier {supplierID: row.SupplierID}) MERGE (supplier)-[:SUPPLIES]->(product);
  • 34. Creating the Relationships USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/products.csv" AS row MATCH (product:Product {productID: row.ProductID}) MATCH (category:Category {categoryID: row.CategoryID}) MERGE (product)-[:PART_OF]->(category); USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/employees.csv" AS row MATCH (employee:Employee {employeeID: row.EmployeeID}) MATCH (manager:Employee {employeeID: row.ReportsTo}) MERGE (employee)-[:REPORTS_TO]->(manager);
  • 35. Creating the Relationships USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row MATCH (order:Order {orderID: row.OrderID}) MATCH (product:Product {productID: row.ProductID}) MERGE (order)-[relation:PRODUCT]->(product) ON CREATE SET relation.unitPrice = toFloat(row.UnitPrice), relation.quantit = toFloat(row.Quantity); USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j- contrib/developer-resources/gh-pages/data/northwind/orders.csv" AS row MATCH (order:Order {orderID: row.OrderID}) MATCH (employee:Employee {employeeID: row.EmployeeID}) MERGE (employee)-[:SOLD]->(order);
  • 36. Recap
  • 37. What we talked about Today #1 #2 #3a #3b
  • 39. Go Forth and Be Graphy.

Editor's Notes

  • #2: So…I’ll be honest, before joining Neo— I don’t think I ever really cared for or considered databases, their architecture, etc. etc. All I cared about was “does it work” and “how much does it cost.” The average developer just wants a database that is going to be easy to use, reliable, and high performance. Brilliant developers want a sandbox that they can do the impossible in, I know, databases are an inherently unsexy topic. If the database is doing it’s job, you forget it (or at least the end-user) will. That’s really why I love Neo4j— it gets your data management issues out of the way as quickly as possible and allows you to be as creative and bold as you wish.
  • #3: The goal of this presentation is to illustrate how easy it is model and query your data in a graph. This is a brief overview of what we’ll be discussing today.
  • #4: First, we’re going to talk about our data, it’s domain, and then think through identifying the relationships inside that data.
  • #5: Next we’ll discuss methods for loading and transforming that data into a graph and persisting it inside Neo4j.
  • #6: Finally, we’ll get to the important part—querying that data. I’ll first show you Neo4j’s built-in query browser, however, in production it’s rare that a user will be probing that data via the browser a la data science, instead most of us will have an application sitting atop our database. We’ll discuss how we can query Neo4j via an application.
  • #7: The Northwind Traders sample database contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. It’s the sample dataset that many of us spun up our first SQL server against.
  • #9: Here was see a database diagram that you’re probably familiar with— we see some arrows drawn between important common items between tables.
  • #10: That’s cool and all…but
  • #11: Taking a step back, let’s consider how we think of people, places, things, and actions. We rarely think of ourselves as a single trait. I am not emailAddress: “kevin@neotechnolgy.com”, rather, I am an entire litany of things, properties that encapsulate who or what I am. In Neo4j, if you so choose, you can create nodes and relationships that mirror the way you think about and consider your world. Here is an employee, they have a name, an id, startDate, birthday, etc, etc. Here is an order, etc. and finally we have the important part, their relationship. We understand this order, based on it’s context. It was sold by this employee.
  • #12: Here we see rather that we can enrich this diagram by naming a relationship between products and categories, orders and who sold them, who supplied a given product…suddenly we see that a RDMSs diagram can easily become a graph. Which is again…pretty cool, but the power will come from what we can do via these relationships
  • #13: This is the final result. We have given nodes-types (we call them labels inside Neo4j), we have relationship types. Not shown here, but later will be touched upon, we can also store key-value pairs on both nodes and relationships. We call these key-value pairs “properties.”
  • #15: normally, we would discuss ETL here, we’ll address it later …but that’s not the most exciting thing to discuss. Let’s jump into the meaty stuff.
  • #29: That’s cool and all…but
  • #30: ## ryans-MacBook-Pro:~ ryanboyd$ sudo easy_install pip ## ryans-MacBook-Pro:~ ryanboyd$ sudo pip install py2neo import py2neo from py2neo import Graph, Path py2neo.set_auth_token('localhost:7474', '2169deeda8ddcf7b38236ddead96d914') graph = Graph("http://localhost:7474/db/data/") cyres = graph.cypher.execute("""MATCH path = (e:Employee)<-[:REPORTS_TO*]-(sub) WITH e, sub, [person in NODES(path) | person.firstName][1..-1] AS path RETURN e.employeeID AS managerID, e.firstName AS managerName, sub.employeeID AS employeeID, sub.firstName AS employeeName, CASE WHEN LENGTH(path) = 0 THEN "Direct Report" ELSE path END AS via ORDER BY LENGTH(path)"""); for record in cyres: print record['via']
  • #31: import py2neo from py2neo import Graph, Path from BaseHTTPServer import BaseHTTPRequestHandler import urlparse HTTP_PORT = 8080 NEO_PROTOCOL = 'http' NEO_HOST = 'localhost' NEO_PORT = 7474 NEO_USER = 'neo4j' NEO_PASSWORD = 'neo4j2' class GetHandler(BaseHTTPRequestHandler): def do_GET(self): response_parts = [ "<html><head>", "<style type='text/css'>", "td,li,h1 { font-family: 'Open Sans','Helvetica Neue','Helvetica','Arial' } ", "</style>", "</head>", "<body>", "<table border='0'><tr><td>" "<img src='http://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-blue-logo.png' />" "</td></tr></table>", "<h1>Employee Relationships</h1>", "<ul>" ] # py2neo.set_auth_token('%s:%s' % (NEO_HOST, NEO_PORT), NEO_AUTH_TOKEN) graph = Graph('%s://%s:%s@%s:%s/db/data/' % (NEO_PROTOCOL, NEO_USER, NEO_PASSWORD, NEO_HOST, NEO_PORT)) cyres = graph.cypher.execute("""MATCH path = (e:Employee)<-[:REPORTS_TO*]-(sub) WITH e, sub, [person in NODES(path) | person.firstName][1..-1] AS path RETURN e.employeeID AS managerID, e.firstName AS managerName, sub.employeeID AS employeeID, sub.firstName AS employeeName, CASE WHEN LENGTH(path) = 0 THEN null ELSE path END AS via ORDER BY LENGTH(path)"""); for record in cyres: response_parts.append("<li>") response_parts.append("<b>%s</b> reports to <b>%s</b>" % (record['employeeName'], record['managerName'])) if isinstance(record['via'], list): response_parts.append("via") response_parts.append("<b>") response_parts.append(','.join(record['via'])) response_parts.append("</b>") response_parts.append("</li>") response_parts.append("</body></html>") message = '\r\n'.join(response_parts) self.send_response(200) self.end_headers() self.wfile.write(message) return if __name__ == '__main__': from BaseHTTPServer import HTTPServer server = HTTPServer(('', HTTP_PORT), GetHandler) print 'Starting server, use <Ctrl-C> to stop' server.serve_forever()
  • #41: We could stop here, we’ve essentially created a document database. We have a vast sea of island-nodes. Some islands are products, some islands are… but if we wanted to know how anything was related to another, we’d have to manually create some sort of join logic.
  • #46: creativity —> well what if we wanted to understand our customers based upon different criteria, insofar as we can change our data model, iteratively, to reflect changing business inputs.