SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Downloaden Sie, um offline zu lesen
Neo4j from the Command Line
Perspective (Introduction)
JUG MK | Skopje | 02.10.2013
2
Speaker Profile
Patrick Baumgartner
•  Senior Software Consultant | Partner @ Swiftmind
•  Spring Framework, OSGi, Neo4j
•  Spring Trainer, Neo4j Fanboy, Agilista
•  Co-Author of „OSGi für Praktiker“
•  Co-Organizer of Neo4j Meetup Zurich
•  @patbaumgartner
3
Swiftmind
Your experts for Enterprise Java
Areas of expertise
•  Java EE
•  Spring Framework
•  OSGi
•  Agile Methodologies
•  Software Engineering Best Practices
Headquarter
•  Zürich, Schweiz
•  @swiftmind
•  http://www.swiftmind.com
4
Agenda
•  Introduction to Graphs
•  Use cases
•  Neo4j
•  Querying
•  Import / Export
•  Tools und APIs
•  Polyglot Persistence
•  Q & A
5
New Demands on Data Access
•  Structured and
unstructured data
•  Massive amounts of data
•  Inexpensive horizontal
scaling
•  Apps and data in the
cloud
•  Social network features
•  …
6
New Types of Data Stores
7
NoSQL
Data Volume
Data Complexity
Key-Value Stores
Column Family
Document Databases
Graph Databases
Relational Databases
90% of all use cases
8
Property Graph Model
•  Graphs are made of
–  Vertices / Nodes
–  Edges / Relationships
–  Properties
Alice
Bob
Car
name:Bob
age:63
sex:male
name:Alice
age:21
sex:female
type:car
vendor:tesla
type:OWNS
type:DRIVES
9
Where is my graph?
Use cases
10
Social Data
Alice
Carol Luke
Bob
Sam
Pete
KNOWS
KNOWS
KNOWS
KNOWS
11
Is it the only use case?
Social Graph
12
Spatial Data
1
2 5
3
13
8
ROAD
ROAD
ROAD
type:ROADlength:3km
type:Hotel
name:Radisson
lat:47.452549
long:8.564615
type:Hotel
name:Widder
lat:47.373517
long:8.539252
13
Social & Spatial Data
Alice
Mat 5
Bob
13
8
ROAD
ROAD
LIKES
KNOWS
type:Hotel
name:Radisson Blu
lat:47.452549
long:8.564615
14
Financial Data
Alice
Hotel Luke
Bank
ATM
Pete
WITHDRAW
TRANSFER
OWNS
15
Other graph use cases?
16
Railroad in Switzerland
17
Your Business Domain
Process
KPI
Device
Activity
Function
Service
CONTAINS
DEPENDS
18
Neo4j
The Big Picture
19
Neo4j – Big Picture
•  Most used graph data base
–  Robust & Mature: in production 24/7 since 2003
–  Community: Ecosystem with Tools, Bindings,
Frameworks
•  Licenses
–  AGPLv3 Community Edition – OpenSource
–  Advanced/Enterprise – for commercial applications
•  Neo Technology
–  Development & Support
–  ~ 50 Persons / 6 Countries / 3 Continents
20
Features
•  Object oriented, flexible network structure
•  ACID transactions
•  Horizontal scalable
•  Java API
–  Java, Groovy, Scala, JRuby
•  Runtime
–  Standalone Server
–  Embedded Database
•  Disk based storage manager
•  Plugin and testing support
21
How do I find my data?
Querying
22
Graph Querying
•  How do I query the right nodes from the graph?
–  Tell me all friends of friends of friends who liked the
movie XYZ with more than 3 stars
–  ...
•  Querying methods
–  Traversing with Neo4j API
–  Traversal descriptions
–  Graph algorithms
–  Index queries
–  Cypher queries
23
Neo4j API
Node bob = ...;	
	
for ((Relationship rel: bob.getRelationships(RelTypes.KNOWS)) {	
Node friend = rel.getEndNode();	
System.out.println(friend.getProperty("name"));	
}	
•  Simple, but very low level API
•  To verbose for complex traversals
24
Traversal API
•  Querying API for graphs
•  Describes paths trough the graph
•  Call back based
•  Fluent API
•  Several predefined constructs
•  Neo4j implements the following graph algorithms:
–  A*
–  Dijkstra
–  pathsWithLength
–  shortestPath
–  allSimplePaths
–  allPaths
25
Traversal API – Constructs
26
Example: Traversal API
TraversalDescription directFriends = Traversal.description()	
	 	.breadthFirst()	
	 	.relationships(RelTypes.KNOWS)	
	 	.evaluator(Evaluators.toDepth(1))	
	 	.evaluator(Evaluators.excludeStartPosition());	
	
	
for(Path p : directFriends.traverse(bob)) {	
	System.out.println(p.endNode().getProperty(„firstname“));	
}
27
Index Queries
•  Support for node and relationship
indices
•  Lucene as default implementation
node id property value
15 name Alice
15 yearOfBirth 1972
16 name Bob
46 name Carol
46 yearOfBirth 1983
28
Cypher Query Language
•  Graph query language similar to SQL
•  Declarative language
•  Defines „What“ and not „How“
•  Uses pattern matching
•  Support for
–  Filters
–  Pagination
•  Supports CRUD functionality
29
Cypher Query Language – Elemente
Element Description
START Start element(s) (index- or id-lookup)
MATCH Pattern to find nodes, describes paths
(a) –[knows]-> (b)
WHERE Result filter (boolean expression)
SKIP LIMIT Pagination
RETURN Defines return elements
ORDER BY Sorting by properties
PARAMETERS Parameter-Map, die im Cypher mittels Key oder
Position verwendet werden kann
CREATE Creates node nodes and relations
SET Updates properties on nodes and relations
DELETE Deletes unused nodes or relationships
30
Example: Cypher Query
String query = "START person=node(12) “	
	+ “MATCH person-[:KNOWS]-friend “	
	+ “RETURN friend“;	
	
	
ExecutionEngine engine = new ExecutionEngine(graphDb);	
ExecutionResult result = engine.execute(query);	
	 	 		
Iterator<Object> column = result.columnAs("friend");	
while(column.hasNext()) {	
	Node friendNode = (Node)column.next();	
	System.out.println(friendNode.getProperty(PROP_FIRSTNAME));	
}
person friend
KNOWS
31
Example: Cypher Create Query
CREATE (carol {name:“Carol“}) return carol; 	
	
+------------------------+	
| carol 	 |	
+------------------------+	
| Node[1]{name:“carol“} |	
+------------------------+	
	
START carol=node(1) CREATE (bob {name:“Bob"}), 	
	 (bob)-[:knows]->(carol) return carol;	
	
	
START carol=node(1) 	
CREATE (apple {name:“Apple“,type:“Fruit“}), 	
(carol)-[:owns {number: 5}]->(apple);	
Carol Bob
KNOWS
Carol
Carol Apple
type: Fruit
OWNS
number: 5
32
Shipping data
Import / Export – Node Manipulation
33
Node Creation with Java
org.neo4j.graphdb.GraphDatabaseService graphDb = 	 	 	
	 	new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);	
Transaction tx = graphDb.beginTx();	
	
try {	
	Node peter = createNode(graphDb, “Alice");	
	Node carol = createNode(graphDb, “Carol"); 	 	 		
	peter.createRelationshipTo(carol, RelTypes.KNOWS);	
	..	
	tx.success();	
} finally {tx.finish();}	
	
public Node createNode(GraphDatabaseService graphDb, String firstname) {	
	Node person = graphDb.createNode();	
	person.setProperty(„firstname“, firstname);	
	return person;	
}
Alice Carol
KNOWS
34
NeoClipse
35
Spring Data Neo4j (SDN)
•  POJOs mapped as nodes or relationships – type safe
•  Works directly Database, typically embedded mode
•  Data is fetched very fast and lazy
•  Stores everything within a @Transaction
•  Uses heavily AspectJ magic to enhance the POJOs
•  …
36
Spring Data Neo4j – Entity
_type_: com.example.Person
name: "Alice"
age: 42
@NodeEntity
public class Person {
private String name;
private int age;
// getters/setters…
}
Person alice = new Person();
alice.setName("Alice");
alice.setAge(42);
alice.persist();
Node
37
Spring Data Neo4j – NodeEntity
@NodeEntity
public class Person {
private String name;
private int yearOfBirth;
@RelatedTo(type = "KNOWS", direction = Direction.OUTGOING)
private Set<Person> knownPersons;
public void knows(Person p) {
knownPersons.add(p);
}
public Set<Person> getFriends() {
return knownPersons;
}
}
Person alice = ...;
alice.knows(bob);
alice.knows(carol);
Alice Bob
KNOWS
Carol
KNOWS
38
Spring Data Neo4j – Relationship
@RelationshipEntity
public class Knows {
private int sinceYear;
public Knows since(int year) {
this.sinceYear = year;
return this;
}
}
@NodeEntity
public class Person {
public Known knows(Person p) {
return this.relateTo(p, Knows.class, "KNOWS");
}
}
Person alice = ...;
Person bob ...;
alice.knows(bob).since(2012); Alice Bob
KNOWS
since: 2012
39
Spring Data Neo4j – Repository
public interface PersonRepository extends
GraphRepository<Person> {
@Query("start person = {0} match ... return ...")
Iterable<Product> getOwnedServices(Person person);
Iterable<Person> findByName(String name);
Iterable<Person> findByNameLike(String name);
}
@Autowired
PersonRepository personRepository;
Person alice = personRepository.findByName("Alice");
40
Thinkerpop Blueprint
Thinkerpop Blueprint
Extensions
•  GraphML Reader/Writer
Library
•  GraphSon Reader/Writer
Library
•  GML Reader/Writer Library
•  Java Universal Network/
Graph Framework
41
GraphML
•  GraphML (http://graphml.graphdrawing.org/ )
–  Standardized format
–  Tool support
–  Pure and simple XML
<graph id="G" edgedefault="directed"> 	
<node id="n0"/> 	
<node id="n1"/>	
	 <edge source="n0" target="n1"/>	
</graph>
42
Neo4j Tools
•  GraphML
–  Gremlin Plugin (no further development)
–  Thinkerpop Blueprint Extensions
•  CSV
–  BatchInserter
–  ParallelBatchInserter
43
Useful tools for your daily work
Tools & APIs
44
Tools & APIs (2)
•  Web console
–  Data overview
–  Querying and visual graph presentation
–  „Command line“
•  Neo4j Shell
–  Command line
–  Sends UNIX-like Commands via RMI (cd, ls, pwd)
–  Cypher Queries Support
•  REST API
–  JSON
–  Clients for Java, .NET, PHP, Ruby, …
•  Neoclipse
–  Visual presentation of the graph
–  Filter options for partial graph presentation
45
What?! Your app uses only one DB?
Polyglot Persistence
46
Polyglot Persistence
Web shop application
User Sessions Shopping Cart Recommendations
Product Catalog Analytics Financial Data
Redis Riak Neo4j
MongoDB Casandra MySQL
47
Neo4j on Meetup.com
48
Q&A
49
Thank you!
Patrick Baumgartner, @patbaumgartner
patrick.baumgartner [at] swiftmind [dot] com
http://www.swiftmind.com @swiftmind

Weitere ähnliche Inhalte

Was ist angesagt?

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_db
Romain Testard
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
Jeff Yemin
 

Was ist angesagt? (17)

greenDAO
greenDAOgreenDAO
greenDAO
 
Grails and Neo4j
Grails and Neo4jGrails and Neo4j
Grails and Neo4j
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4j
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_db
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Graph Analytics: Graph Algorithms Inside Neo4j
Graph Analytics: Graph Algorithms Inside Neo4jGraph Analytics: Graph Algorithms Inside Neo4j
Graph Analytics: Graph Algorithms Inside Neo4j
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Challenges in knowledge graph visualization
Challenges in knowledge graph visualizationChallenges in knowledge graph visualization
Challenges in knowledge graph visualization
 
Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...Designing and Building a Graph Database Application – Architectural Choices, ...
Designing and Building a Graph Database Application – Architectural Choices, ...
 
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1
 

Andere mochten auch

OECD Health Indicators at a Glance
OECD Health Indicators at a GlanceOECD Health Indicators at a Glance
OECD Health Indicators at a Glance
Dale Sanders
 
The 12 Criteria of Population Health Management
The 12 Criteria of Population Health ManagementThe 12 Criteria of Population Health Management
The 12 Criteria of Population Health Management
Dale Sanders
 
HIMSS National Data Warehousing Webinar
HIMSS National Data Warehousing WebinarHIMSS National Data Warehousing Webinar
HIMSS National Data Warehousing Webinar
Dale Sanders
 
An Overview of Disease Registries
An Overview of Disease RegistriesAn Overview of Disease Registries
An Overview of Disease Registries
Dale Sanders
 
Choosing an Analytics Solution in Healthcare
Choosing an Analytics Solution in HealthcareChoosing an Analytics Solution in Healthcare
Choosing an Analytics Solution in Healthcare
Dale Sanders
 
Late Binding in Data Warehouses
Late Binding in Data WarehousesLate Binding in Data Warehouses
Late Binding in Data Warehouses
Dale Sanders
 
Healthcare 2.0: The Age of Analytics
Healthcare 2.0: The Age of AnalyticsHealthcare 2.0: The Age of Analytics
Healthcare 2.0: The Age of Analytics
Dale Sanders
 

Andere mochten auch (20)

Reco4J @ London Meetup (June 26th)
Reco4J @ London Meetup (June 26th)Reco4J @ London Meetup (June 26th)
Reco4J @ London Meetup (June 26th)
 
Population Health Management
Population Health ManagementPopulation Health Management
Population Health Management
 
Microsoft: A Waking Giant in Healthcare Analytics and Big Data
Microsoft: A Waking Giant in Healthcare Analytics and Big DataMicrosoft: A Waking Giant in Healthcare Analytics and Big Data
Microsoft: A Waking Giant in Healthcare Analytics and Big Data
 
Reco4 @ Paris Meetup (May 20th)
Reco4 @ Paris Meetup (May 20th)Reco4 @ Paris Meetup (May 20th)
Reco4 @ Paris Meetup (May 20th)
 
OECD Health Indicators at a Glance
OECD Health Indicators at a GlanceOECD Health Indicators at a Glance
OECD Health Indicators at a Glance
 
Reco4J @ Munich Meetup (April 18th)
Reco4J @ Munich Meetup (April 18th)Reco4J @ Munich Meetup (April 18th)
Reco4J @ Munich Meetup (April 18th)
 
Managing National Health: An Overview of Metrics & Options
Managing National Health: An Overview of Metrics & OptionsManaging National Health: An Overview of Metrics & Options
Managing National Health: An Overview of Metrics & Options
 
Break All The Rules: What the Leading Health Systems Do Differently with Anal...
Break All The Rules: What the Leading Health Systems Do Differently with Anal...Break All The Rules: What the Leading Health Systems Do Differently with Anal...
Break All The Rules: What the Leading Health Systems Do Differently with Anal...
 
Is Big Data a Big Deal... or Not?
Is Big Data a Big Deal... or Not?Is Big Data a Big Deal... or Not?
Is Big Data a Big Deal... or Not?
 
Precise Patient Registries for Clinical Research and Population Management
Precise Patient Registries for Clinical Research and Population ManagementPrecise Patient Registries for Clinical Research and Population Management
Precise Patient Registries for Clinical Research and Population Management
 
The 12 Criteria of Population Health Management
The 12 Criteria of Population Health ManagementThe 12 Criteria of Population Health Management
The 12 Criteria of Population Health Management
 
Predicting the Future of Predictive Analytics in Healthcare
Predicting the Future of Predictive Analytics in HealthcarePredicting the Future of Predictive Analytics in Healthcare
Predicting the Future of Predictive Analytics in Healthcare
 
HIMSS National Data Warehousing Webinar
HIMSS National Data Warehousing WebinarHIMSS National Data Warehousing Webinar
HIMSS National Data Warehousing Webinar
 
Healthcare Best Practices in Data Warehousing & Analytics
Healthcare Best Practices in Data Warehousing & AnalyticsHealthcare Best Practices in Data Warehousing & Analytics
Healthcare Best Practices in Data Warehousing & Analytics
 
An Overview of Disease Registries
An Overview of Disease RegistriesAn Overview of Disease Registries
An Overview of Disease Registries
 
Strategic Options for Analytics in Healthcare
Strategic Options for Analytics in HealthcareStrategic Options for Analytics in Healthcare
Strategic Options for Analytics in Healthcare
 
Choosing an Analytics Solution in Healthcare
Choosing an Analytics Solution in HealthcareChoosing an Analytics Solution in Healthcare
Choosing an Analytics Solution in Healthcare
 
Late Binding in Data Warehouses
Late Binding in Data WarehousesLate Binding in Data Warehouses
Late Binding in Data Warehouses
 
Healthcare Billing and Reimbursement: Starting from Scratch
Healthcare Billing and Reimbursement: Starting from ScratchHealthcare Billing and Reimbursement: Starting from Scratch
Healthcare Billing and Reimbursement: Starting from Scratch
 
Healthcare 2.0: The Age of Analytics
Healthcare 2.0: The Age of AnalyticsHealthcare 2.0: The Age of Analytics
Healthcare 2.0: The Age of Analytics
 

Ähnlich wie Neo4j Introduction (for Techies)

The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
Neo4j
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 

Ähnlich wie Neo4j Introduction (for Techies) (20)

Using Neo4j from Java
Using Neo4j from JavaUsing Neo4j from Java
Using Neo4j from Java
 
Cypher and apache spark multiple graphs and more in open cypher
Cypher and apache spark  multiple graphs and more in  open cypherCypher and apache spark  multiple graphs and more in  open cypher
Cypher and apache spark multiple graphs and more in open cypher
 
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
Neo4j Morpheus: Interweaving Table and Graph Data with SQL and Cypher in Apac...
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for Graphs
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
 
Discover GraphQL with Python, Graphene and Odoo
Discover GraphQL with Python, Graphene and OdooDiscover GraphQL with Python, Graphene and Odoo
Discover GraphQL with Python, Graphene and Odoo
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
Document Model for High Speed Spark Processing
Document Model for High Speed Spark ProcessingDocument Model for High Speed Spark Processing
Document Model for High Speed Spark Processing
 
OSMC 2009 | Icinga by Icinga Team
OSMC 2009 | Icinga by Icinga TeamOSMC 2009 | Icinga by Icinga Team
OSMC 2009 | Icinga by Icinga Team
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from Scratch
 
Naver_alternative_to_jpa
Naver_alternative_to_jpaNaver_alternative_to_jpa
Naver_alternative_to_jpa
 
Morpheus SQL and Cypher® in Apache® Spark - Big Data Meetup Munich
Morpheus SQL and Cypher® in Apache® Spark - Big Data Meetup MunichMorpheus SQL and Cypher® in Apache® Spark - Big Data Meetup Munich
Morpheus SQL and Cypher® in Apache® Spark - Big Data Meetup Munich
 
Morpheus - SQL and Cypher in Apache Spark
Morpheus - SQL and Cypher in Apache SparkMorpheus - SQL and Cypher in Apache Spark
Morpheus - SQL and Cypher in Apache Spark
 
Cassandra drivers and libraries
Cassandra drivers and librariesCassandra drivers and libraries
Cassandra drivers and libraries
 
Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMC
 
Processing Large Graphs
Processing Large GraphsProcessing Large Graphs
Processing Large Graphs
 
AgensGraph Presentation at PGConf.us 2017
AgensGraph Presentation at PGConf.us 2017AgensGraph Presentation at PGConf.us 2017
AgensGraph Presentation at PGConf.us 2017
 
State of search | drupalcon dublin
State of search | drupalcon dublinState of search | drupalcon dublin
State of search | drupalcon dublin
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 

Mehr von Patrick Baumgartner

Daten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4jDaten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4j
Patrick Baumgartner
 
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGiOSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
Patrick Baumgartner
 

Mehr von Patrick Baumgartner (9)

Customer is king
Customer is kingCustomer is king
Customer is king
 
Daten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4jDaten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4j
 
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow ZurichHow to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
 
BED-Con - Tools für den täglichen Kampf als Entwickler
BED-Con - Tools für den täglichen Kampf als EntwicklerBED-Con - Tools für den täglichen Kampf als Entwickler
BED-Con - Tools für den täglichen Kampf als Entwickler
 
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, OehmichenJFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
 
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGiOSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
 
Pax – Tools für den OSGi Alltag
Pax – Tools für den OSGi AlltagPax – Tools für den OSGi Alltag
Pax – Tools für den OSGi Alltag
 
OSGi with the Spring Framework
OSGi with the Spring FrameworkOSGi with the Spring Framework
OSGi with the Spring Framework
 
Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Neo4j Introduction (for Techies)

  • 1. Neo4j from the Command Line Perspective (Introduction) JUG MK | Skopje | 02.10.2013
  • 2. 2 Speaker Profile Patrick Baumgartner •  Senior Software Consultant | Partner @ Swiftmind •  Spring Framework, OSGi, Neo4j •  Spring Trainer, Neo4j Fanboy, Agilista •  Co-Author of „OSGi für Praktiker“ •  Co-Organizer of Neo4j Meetup Zurich •  @patbaumgartner
  • 3. 3 Swiftmind Your experts for Enterprise Java Areas of expertise •  Java EE •  Spring Framework •  OSGi •  Agile Methodologies •  Software Engineering Best Practices Headquarter •  Zürich, Schweiz •  @swiftmind •  http://www.swiftmind.com
  • 4. 4 Agenda •  Introduction to Graphs •  Use cases •  Neo4j •  Querying •  Import / Export •  Tools und APIs •  Polyglot Persistence •  Q & A
  • 5. 5 New Demands on Data Access •  Structured and unstructured data •  Massive amounts of data •  Inexpensive horizontal scaling •  Apps and data in the cloud •  Social network features •  …
  • 6. 6 New Types of Data Stores
  • 7. 7 NoSQL Data Volume Data Complexity Key-Value Stores Column Family Document Databases Graph Databases Relational Databases 90% of all use cases
  • 8. 8 Property Graph Model •  Graphs are made of –  Vertices / Nodes –  Edges / Relationships –  Properties Alice Bob Car name:Bob age:63 sex:male name:Alice age:21 sex:female type:car vendor:tesla type:OWNS type:DRIVES
  • 9. 9 Where is my graph? Use cases
  • 11. 11 Is it the only use case? Social Graph
  • 13. 13 Social & Spatial Data Alice Mat 5 Bob 13 8 ROAD ROAD LIKES KNOWS type:Hotel name:Radisson Blu lat:47.452549 long:8.564615
  • 19. 19 Neo4j – Big Picture •  Most used graph data base –  Robust & Mature: in production 24/7 since 2003 –  Community: Ecosystem with Tools, Bindings, Frameworks •  Licenses –  AGPLv3 Community Edition – OpenSource –  Advanced/Enterprise – for commercial applications •  Neo Technology –  Development & Support –  ~ 50 Persons / 6 Countries / 3 Continents
  • 20. 20 Features •  Object oriented, flexible network structure •  ACID transactions •  Horizontal scalable •  Java API –  Java, Groovy, Scala, JRuby •  Runtime –  Standalone Server –  Embedded Database •  Disk based storage manager •  Plugin and testing support
  • 21. 21 How do I find my data? Querying
  • 22. 22 Graph Querying •  How do I query the right nodes from the graph? –  Tell me all friends of friends of friends who liked the movie XYZ with more than 3 stars –  ... •  Querying methods –  Traversing with Neo4j API –  Traversal descriptions –  Graph algorithms –  Index queries –  Cypher queries
  • 23. 23 Neo4j API Node bob = ...; for ((Relationship rel: bob.getRelationships(RelTypes.KNOWS)) { Node friend = rel.getEndNode(); System.out.println(friend.getProperty("name")); } •  Simple, but very low level API •  To verbose for complex traversals
  • 24. 24 Traversal API •  Querying API for graphs •  Describes paths trough the graph •  Call back based •  Fluent API •  Several predefined constructs •  Neo4j implements the following graph algorithms: –  A* –  Dijkstra –  pathsWithLength –  shortestPath –  allSimplePaths –  allPaths
  • 25. 25 Traversal API – Constructs
  • 26. 26 Example: Traversal API TraversalDescription directFriends = Traversal.description() .breadthFirst() .relationships(RelTypes.KNOWS) .evaluator(Evaluators.toDepth(1)) .evaluator(Evaluators.excludeStartPosition()); for(Path p : directFriends.traverse(bob)) { System.out.println(p.endNode().getProperty(„firstname“)); }
  • 27. 27 Index Queries •  Support for node and relationship indices •  Lucene as default implementation node id property value 15 name Alice 15 yearOfBirth 1972 16 name Bob 46 name Carol 46 yearOfBirth 1983
  • 28. 28 Cypher Query Language •  Graph query language similar to SQL •  Declarative language •  Defines „What“ and not „How“ •  Uses pattern matching •  Support for –  Filters –  Pagination •  Supports CRUD functionality
  • 29. 29 Cypher Query Language – Elemente Element Description START Start element(s) (index- or id-lookup) MATCH Pattern to find nodes, describes paths (a) –[knows]-> (b) WHERE Result filter (boolean expression) SKIP LIMIT Pagination RETURN Defines return elements ORDER BY Sorting by properties PARAMETERS Parameter-Map, die im Cypher mittels Key oder Position verwendet werden kann CREATE Creates node nodes and relations SET Updates properties on nodes and relations DELETE Deletes unused nodes or relationships
  • 30. 30 Example: Cypher Query String query = "START person=node(12) “ + “MATCH person-[:KNOWS]-friend “ + “RETURN friend“; ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result = engine.execute(query); Iterator<Object> column = result.columnAs("friend"); while(column.hasNext()) { Node friendNode = (Node)column.next(); System.out.println(friendNode.getProperty(PROP_FIRSTNAME)); } person friend KNOWS
  • 31. 31 Example: Cypher Create Query CREATE (carol {name:“Carol“}) return carol; +------------------------+ | carol | +------------------------+ | Node[1]{name:“carol“} | +------------------------+ START carol=node(1) CREATE (bob {name:“Bob"}), (bob)-[:knows]->(carol) return carol; START carol=node(1) CREATE (apple {name:“Apple“,type:“Fruit“}), (carol)-[:owns {number: 5}]->(apple); Carol Bob KNOWS Carol Carol Apple type: Fruit OWNS number: 5
  • 32. 32 Shipping data Import / Export – Node Manipulation
  • 33. 33 Node Creation with Java org.neo4j.graphdb.GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); Transaction tx = graphDb.beginTx(); try { Node peter = createNode(graphDb, “Alice"); Node carol = createNode(graphDb, “Carol"); peter.createRelationshipTo(carol, RelTypes.KNOWS); .. tx.success(); } finally {tx.finish();} public Node createNode(GraphDatabaseService graphDb, String firstname) { Node person = graphDb.createNode(); person.setProperty(„firstname“, firstname); return person; } Alice Carol KNOWS
  • 35. 35 Spring Data Neo4j (SDN) •  POJOs mapped as nodes or relationships – type safe •  Works directly Database, typically embedded mode •  Data is fetched very fast and lazy •  Stores everything within a @Transaction •  Uses heavily AspectJ magic to enhance the POJOs •  …
  • 36. 36 Spring Data Neo4j – Entity _type_: com.example.Person name: "Alice" age: 42 @NodeEntity public class Person { private String name; private int age; // getters/setters… } Person alice = new Person(); alice.setName("Alice"); alice.setAge(42); alice.persist(); Node
  • 37. 37 Spring Data Neo4j – NodeEntity @NodeEntity public class Person { private String name; private int yearOfBirth; @RelatedTo(type = "KNOWS", direction = Direction.OUTGOING) private Set<Person> knownPersons; public void knows(Person p) { knownPersons.add(p); } public Set<Person> getFriends() { return knownPersons; } } Person alice = ...; alice.knows(bob); alice.knows(carol); Alice Bob KNOWS Carol KNOWS
  • 38. 38 Spring Data Neo4j – Relationship @RelationshipEntity public class Knows { private int sinceYear; public Knows since(int year) { this.sinceYear = year; return this; } } @NodeEntity public class Person { public Known knows(Person p) { return this.relateTo(p, Knows.class, "KNOWS"); } } Person alice = ...; Person bob ...; alice.knows(bob).since(2012); Alice Bob KNOWS since: 2012
  • 39. 39 Spring Data Neo4j – Repository public interface PersonRepository extends GraphRepository<Person> { @Query("start person = {0} match ... return ...") Iterable<Product> getOwnedServices(Person person); Iterable<Person> findByName(String name); Iterable<Person> findByNameLike(String name); } @Autowired PersonRepository personRepository; Person alice = personRepository.findByName("Alice");
  • 40. 40 Thinkerpop Blueprint Thinkerpop Blueprint Extensions •  GraphML Reader/Writer Library •  GraphSon Reader/Writer Library •  GML Reader/Writer Library •  Java Universal Network/ Graph Framework
  • 41. 41 GraphML •  GraphML (http://graphml.graphdrawing.org/ ) –  Standardized format –  Tool support –  Pure and simple XML <graph id="G" edgedefault="directed"> <node id="n0"/> <node id="n1"/> <edge source="n0" target="n1"/> </graph>
  • 42. 42 Neo4j Tools •  GraphML –  Gremlin Plugin (no further development) –  Thinkerpop Blueprint Extensions •  CSV –  BatchInserter –  ParallelBatchInserter
  • 43. 43 Useful tools for your daily work Tools & APIs
  • 44. 44 Tools & APIs (2) •  Web console –  Data overview –  Querying and visual graph presentation –  „Command line“ •  Neo4j Shell –  Command line –  Sends UNIX-like Commands via RMI (cd, ls, pwd) –  Cypher Queries Support •  REST API –  JSON –  Clients for Java, .NET, PHP, Ruby, … •  Neoclipse –  Visual presentation of the graph –  Filter options for partial graph presentation
  • 45. 45 What?! Your app uses only one DB? Polyglot Persistence
  • 46. 46 Polyglot Persistence Web shop application User Sessions Shopping Cart Recommendations Product Catalog Analytics Financial Data Redis Riak Neo4j MongoDB Casandra MySQL
  • 49. 49 Thank you! Patrick Baumgartner, @patbaumgartner patrick.baumgartner [at] swiftmind [dot] com http://www.swiftmind.com @swiftmind