JugMarche: Neo4j 2 (Cypher)

920 views

Published on

Slides of the JugMarche June meeting, about Neo4j and Cypher

Published in: Software, Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
920
On SlideShare
0
From Embeds
0
Number of Embeds
45
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

JugMarche: Neo4j 2 (Cypher)

  1. 1. Neo4j 2: Learning Cypher JUG Marche - June 2014 Onofrio Panzarino
  2. 2. Graph databases and me ● RDF (Semantic web) ○ 2004-2005: Sesame (SPARQL) ● Neo4j ○ 2011: Java API (Embedded), Traversers ○ 2013: Cypher Twitter: @onof80 Blog: http://learningcypher.blogspot.com My book: Learning Cypher
  3. 3. What is Neo4j - Graph database - ACID transaction - 2 running modes > Embedded (JAVA API) > Server (REST) - Cypher Query Language
  4. 4. Model: nodes and relationships Source: http://gist.neo4j.org/?8635758
  5. 5. Schema? Schemaless (key- value) Nodes: > properties Relationships: > properties Schema Nodes: 0+ Labels Relationships: 1 Type Indexes+Constraints
  6. 6. Querying: REST API Properties of node with id 32: GET http://localhost:7474/db/data/node/32/properties { "user": "@onof80", "lastLogin": 1394304000, "tags": ["Java","Scala","NoSql"] }
  7. 7. Traversing the graph for ( Path position : db.traversalDescription() .depthFirst() .relationships( Rels.KNOWS, Direction.INCOMING ) .evaluator( Evaluators.toDepth( 5 ) ) .traverse( node6 ) ) { output += position + "n"; } (6) (6)<--[KNOWS,1]--(3) (6)<--[KNOWS,1]--(3)<--[KNOWS,6]--(0) (6)<--[KNOWS,1]--(3)<--[KNOWS,6]--(0)<--[KNOWS,4]--(5) Powerful but hardcoded
  8. 8. Querying with Cypher START n=node(10) MATCH path =(n)<-[:KNOWS*0..5]-() RETURN path http://console.neo4j.org/
  9. 9. Create a full path CREATE (a:Language { name: "Java"}), (b:Language { name: "Scala" }), (c:Language { name: "JavaScript" }), (jvm:Platfom { name: "JVM" }), path=(a)-[r:RUNS_ON]->(jvm) <-[r2:RUNS_ON]-(b) RETURN path
  10. 10. MERGE Look for a pattern: ● Found? Match it ● Else create it MERGE (a:Language { name: "Java" }) SET a.version = 8 RETURN a
  11. 11. Idempotent operations MATCH (a:Language) REMOVE a.version MATCH (a:Language) DELETE a
  12. 12. But... MERGE (a:Language { name: "Java" }) ON MATCH SET a.version = a.version + 1 ON CREATE SET a.version = 1 RETURN a
  13. 13. Optional paths MATCH (a:Language) OPTIONAL MATCH (a)-[:RUNS_ON]-(b) RETURN a,b ORDER BY a.name
  14. 14. Aggregations MATCH (a:Language) OPTIONAL MATCH (a)-[:RUNS_ON]-(b) RETURN b.name, COUNT(*)
  15. 15. Other keywords Splitting queries WITH Manipulating collections EXTRACT, FILTER, REDUCE Predicates ALL, ANY, SINGLE, NONE
  16. 16. More features Integration LOAD CSV WITH HEADERS FROM <file> AS line CREATE ... Profiling PROFILE <query>
  17. 17. Too simple domain? http://gist.neo4j.org/
  18. 18. Any questions? Q&A More infos: http://docs.neo4j.org/ My book All Neo4j books

×