An Introduc/on to Neo4j @iansrobinson - - PowerPoint PPT Presentation
An Introduc/on to Neo4j @iansrobinson - - PowerPoint PPT Presentation
An Introduc/on to Neo4j @iansrobinson ian.robinson@neotechnology.com #neo4j Neo4j is a Graph Database #neo4j Neo4j is a Graph Database #neo4j Neo4j is a Graph Database #neo4j
#neo4j
Neo4j ¡is ¡a ¡Graph ¡Database
#neo4j
Neo4j ¡is ¡a ¡Graph ¡Database
#neo4j
Neo4j ¡is ¡a ¡Graph ¡Database
#neo4j
Neo4j ¡is ¡a ¡Graph ¡Database
#neo4j
Neo4j ¡is ¡a ¡Graph ¡Database
#neo4j
Nodes ¡& ¡Proper/es
#neo4j
Nodes ¡& ¡Proper/es
#neo4j
Nodes ¡& ¡Proper/es
#neo4j
Rela/onships
#neo4j
Rela/onships
#neo4j
Neo4j
32 ¡billion ¡nodes 32 ¡billion ¡rela/onships 64 ¡billion ¡proper/es
#neo4j
#neo4j
#neo4j
How ¡do ¡I ¡query ¡the ¡data?
hIp://opfm.jpl.nasa.gov/ hIp://news.xinhuanet.com
Why ¡Neo4j?
Why ¡Neo4j?
Schema-‑free
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
ACID ¡transac2ons
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
ACID ¡transac2ons
- Durable, ¡consistent ¡data
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
ACID ¡transac2ons
- Durable, ¡consistent ¡data
Performance
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
ACID ¡transac2ons
- Durable, ¡consistent ¡data
Performance
- Millions ¡of ¡‘joins’ ¡per ¡second
Why ¡Neo4j?
Schema-‑free
- Complex, ¡densely-‑connected ¡datasets
ACID ¡transac2ons
- Durable, ¡consistent ¡data
Performance
- Millions ¡of ¡‘joins’ ¡per ¡second
- Consistent ¡query ¡/mes ¡as ¡dataset ¡grows
from
stole from
stole from enemy
stole from enemy enemy
stole from enemy enemy enemy
stole from enemy enemy companion companion enemy
stole from loves loves enemy enemy companion companion enemy
stole from loves loves enemy enemy
Victory ¡of ¡ the ¡Daleks
appeared ¡ in appeared ¡ in companion companion enemy
stole from loves loves enemy enemy
A ¡Good ¡Man ¡ Goes ¡to ¡War
appeared ¡ in appeared ¡ in appeared ¡ in appeared ¡ in
Victory ¡of ¡ the ¡Daleks
appeared ¡ in appeared ¡ in companion companion enemy
GraphDatabaseService db = new EmbeddedGraphDatabase("/data/drwho");
GraphDatabaseService db = new EmbeddedGraphDatabase("/data/drwho"); Node theDoctor = db.createNode(); theDoctor.setProperty("name", "The Doctor"); Node daleks = db.createNode(); daleks.setProperty("name", "Daleks"); Node cybermen = db.createNode(); cybermen.setProperty("name", "Cybermen");
GraphDatabaseService db = new EmbeddedGraphDatabase("/data/drwho"); Node theDoctor = db.createNode(); theDoctor.setProperty("name", "The Doctor"); Node daleks = db.createNode(); daleks.setProperty("name", "Daleks"); Node cybermen = db.createNode(); cybermen.setProperty("name", "Cybermen"); theDoctor.createRelationshipTo(daleks, DynamicRelationshipType.withName("ENEMY")); theDoctor.createRelationshipTo(cybermen, DynamicRelationshipType.withName("ENEMY"));
ENEMY ENEMY
GraphDatabaseService db = new EmbeddedGraphDatabase("/data/drwho"); Transaction tx = db.beginTx(); try { Node theDoctor = db.createNode(); theDoctor.setProperty("name", "The Doctor"); Node daleks = db.createNode(); daleks.setProperty("name", "Daleks"); Node cybermen = db.createNode(); cybermen.setProperty("name", "Cybermen"); theDoctor.createRelationshipTo(daleks, DynamicRelationshipType.withName("ENEMY")); theDoctor.createRelationshipTo(cybermen, DynamicRelationshipType.withName("ENEMY"));
ENEMY ENEMY
#neo4j
Cypher
(daleks)<-[:ENEMY]-(doctor)-[:ENEMY]->(cybermen) ENEMY ENEMY
#neo4j
Cypher
(doctor)-[:ENEMY]->(daleks), (doctor)-[:ENEMY]->(cybermen) ENEMY ENEMY
#neo4j
CREATE doctor = {name : 'The Doctor'}, daleks = {name : 'Daleks'}, cybermen = {name : 'Cybermen'}, doctor-[:ENEMY]->daleks, doctor-[:ENEMY]->cybermen RETURN doctor; ENEMY ENEMY
Create ¡Graph ¡Using ¡Cypher
#neo4j
CREATE doctor = {name : 'The Doctor'}, daleks = {name : 'Daleks'}, cybermen = {name : 'Cybermen'}, doctor-[:ENEMY]->daleks, doctor-[:ENEMY]->cybermen RETURN doctor; ENEMY ENEMY
Create ¡Graph ¡Using ¡Cypher
#neo4j
Dalek ¡Props
hIp://www.dalek6388.co.uk/
!tle:Power ¡of ¡ the ¡Daleks species:Dalek APPEARED_IN USED_IN props:Daleks name:Dalek ¡Six-‑5 name:Dalek ¡7 name:Dalek ¡2 name:Dalek ¡1 MEMBER_OF MEMBER_OF type:shoulders type:skirt
name:Dalek ¡Six-‑5 name:Dalek ¡6 name:Dalek ¡5 ORIGINAL_PROP ORIGINAL_PROP ORIGINAL_PROP ORIGINAL_PROP name:Dalek ¡1 name:Dalek ¡2 name:Dalek ¡7
!tle:Power ¡of ¡ the ¡Daleks !tle:The ¡ Daleks !tle:The ¡ Dalek ¡ Invasion ¡of ¡ Earth name:Dalek ¡Two-‑1 name:Dalek ¡One-‑5 name:Dalek ¡Six-‑7
name: Dalek ¡Six-‑5 name:Dalek ¡1 name:Dalek ¡2 name:Dalek ¡7
#neo4j
Supply ¡Chain ¡Traceability
daleks episode part
- riginalprop
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
daleks episode part
- riginalprop
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
(daleks)-‑[:APPEARED_IN]-‑>(episode)<-‑[:USED_IN]-‑
daleks episode part
- riginalprop
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
(daleks)-‑[:APPEARED_IN]-‑>(episode)<-‑[:USED_IN]-‑ ()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡
daleks episode part
- riginalprop
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
(daleks)-‑[:APPEARED_IN]-‑>(episode)<-‑[:USED_IN]-‑ ()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ (part)-‑[:ORIGINAL_PROP]-‑>(originalprop)
daleks episode part
- riginalprop
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
START ¡ ¡daleks=node:species(species='Dalek') ¡ MATCH ¡ ¡daleks-‑[:APPEARED_IN]-‑>episode<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part-‑[:ORIGINAL_PROP]-‑>originalprop RETURN ¡originalprop.name ¡AS ¡prop, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part.type ¡AS ¡part, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡count(episode) ¡AS ¡episode_count, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡collect(episode.2tle) ¡AS ¡episodes ¡ ORDER ¡BY ¡episode_count ¡desc ¡ LIMIT ¡1;
Cypher Query
Index Lookup
START ¡ ¡daleks=node:species(species='Dalek') ¡ MATCH ¡ ¡daleks-‑[:APPEARED_IN]-‑>episode<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part-‑[:ORIGINAL_PROP]-‑>originalprop RETURN ¡originalprop.name ¡AS ¡prop, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part.type ¡AS ¡part, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡count(episode) ¡AS ¡episode_count, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡collect(episode.2tle) ¡AS ¡episodes ¡ ORDER ¡BY ¡episode_count ¡desc ¡ LIMIT ¡1;
Match Nodes & Relationships
START ¡ ¡daleks=node:species(species='Dalek') ¡ MATCH ¡ ¡daleks-‑[:APPEARED_IN]-‑>episode<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part-‑[:ORIGINAL_PROP]-‑>originalprop RETURN ¡originalprop.name ¡AS ¡prop, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part.type ¡AS ¡part, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡count(episode) ¡AS ¡episode_count, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡collect(episode.2tle) ¡AS ¡episodes ¡ ORDER ¡BY ¡episode_count ¡desc ¡ LIMIT ¡1;
Return Values
START ¡ ¡daleks=node:species(species='Dalek') ¡ MATCH ¡ ¡daleks-‑[:APPEARED_IN]-‑>episode<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part-‑[:ORIGINAL_PROP]-‑>originalprop RETURN ¡originalprop.name ¡AS ¡prop, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡part.type ¡AS ¡part, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡count(episode) ¡AS ¡episode_count, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡collect(episode.2tle) ¡AS ¡episodes ¡ ORDER ¡BY ¡episode_count ¡desc ¡ LIMIT ¡1;
In Webadmin
#neo4j
The ¡Hardest ¡Working ¡Prop ¡Part
hIp://www.dalek6388.co.uk/ Dalek ¡One’s ¡shoulders
#neo4j
Download
hIp://neo4j.org/download/
#neo4j
Tutorial
hIps://github.com/jimwebber/neo4j-‑tutorial
#neo4j
Ques/ons?
@iansrobinson ian.robinson@neotechnology.com
daleks episode part
- riginalprop
match ¡(daleks)-‑[:APPEARED_IN]-‑>(episode)<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(part)-‑[:ORIGINAL_PROP]-‑>(originalprop) ¡
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP
daleks episode part
- riginalprop
match ¡(daleks)-‑[:APPEARED_IN]-‑>(episode)<-‑[:USED_IN]-‑ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡()<-‑[:MEMBER_OF]-‑()-‑[:COMPOSED_OF]-‑> ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(part)-‑[:ORIGINAL_PROP]-‑>(originalprop) ¡
APPEARED_IN USED_IN MEMBER_OF COMPOSED_OF ORIGINAL_PROP