Walkthrough Neo4j 1.9 & 2.0

68
Webinar June 25 2013 Walkthrough Neo4j 1.9.1 & 2.0 Michael Hunger, Neo Technology @mesirii

description

This Presentations gives an over

Transcript of Walkthrough Neo4j 1.9 & 2.0

Page 1: Walkthrough Neo4j 1.9 & 2.0

WebinarJune 25 2013

Walkthrough Neo4j 1.9.1 & 2.0Michael Hunger, Neo Technology

@mesirii

Page 2: Walkthrough Neo4j 1.9 & 2.0

Overview

Page 3: Walkthrough Neo4j 1.9 & 2.0

Overview• Neo4j 1.9.1

• High Availability & Operations

• Performance & Cypher

• Neo4j 2.0

• Extension Property Graph Model - Labels & Indexes

• Cypher

• Transactional Http Endpoint

Page 4: Walkthrough Neo4j 1.9 & 2.0

Neo4j 1.9.1

Page 5: Walkthrough Neo4j 1.9 & 2.0

High Availability & Operations• new HA cluster management implementation (paxos) w/o ZK

• ZK compatibility layer for rolling upgrades from 1.8

• faster consistency check with new implementation

• new HA JMX information -> JConsole

• Arbiter instance for clusters < 3

• Slave only mode

• new endpoint for load balancers /db/manage/server/ha/{master,slave}

Page 6: Walkthrough Neo4j 1.9 & 2.0

Hands-On High Availability• Manual 1.8 vs. Manual 1.9

• Live

• 3 node cluster

• runs without zookeeper

• show that replication works

• show management endpoint and JMX

• show config

Page 7: Walkthrough Neo4j 1.9 & 2.0

General• Java 7 support

• Store-Locks to limit access of Readonly-Instances

• Online backup enabled by default, works with port-range

• Performance

• caching & property access improvements

• REST-Batch-Operations speedup

Page 8: Walkthrough Neo4j 1.9 & 2.0

Server• Traversal Javascript is sandboxed

• X-Forwarded-Host and X-Forwarded-Proto headers to support running behind a proxy

• SSL certificate chain support

• REST-batch-operations performance improvements

• Gremlin plugin as separate project

• to allow different versions and decouple from neo4j release cycle

Page 9: Walkthrough Neo4j 1.9 & 2.0

Cypher• upgrade to scala 2.10

• concurrent parsing

• execution plan description

• fix non-lazyness

• faster pattern matcher (bi-directional traversal)

• top-n select for order by limit

Page 10: Walkthrough Neo4j 1.9 & 2.0

Cypher

• predicates as expressions

• Functions: reduce, string functions

• order by, skip, limit with WITH

• automatic conversion

• SET can work with other nodes or maps

Page 11: Walkthrough Neo4j 1.9 & 2.0

Hands-On Cypher

• profiling

• string functions, show reduce

• WITH with ORDER BY LIMIT

• SET with predicates, SET with other nodes

• FOREACH with CREATE UNIQUE

Page 12: Walkthrough Neo4j 1.9 & 2.0

Why 2.0?

Page 13: Walkthrough Neo4j 1.9 & 2.0

(0.x) --> (1.x) --> (2.x)

Page 14: Walkthrough Neo4j 1.9 & 2.0

(0.x) --> (1.x) --> (2.x)

• 0.x was about embedded java

Page 15: Walkthrough Neo4j 1.9 & 2.0

(0.x) --> (1.x) --> (2.x)

• 0.x was about embedded java

• 1.x introduced indexes, the server and REST

Page 16: Walkthrough Neo4j 1.9 & 2.0

(0.x) --> (1.x) --> (2.x)

• 0.x was about embedded java

• 1.x introduced indexes, the server and REST

• 2.x ease of use, big data, cloud

Page 17: Walkthrough Neo4j 1.9 & 2.0

(0.x) --> (1.x) --> (2.x)

• 0.x was about embedded java

• 1.x introduced indexes, the server and REST

• 2.x ease of use, big data, cloud

which means a focus on...

Page 18: Walkthrough Neo4j 1.9 & 2.0

This guy

Page 19: Walkthrough Neo4j 1.9 & 2.0

Focus on Cypher

Page 20: Walkthrough Neo4j 1.9 & 2.0

Focus on Cypher

• Cypher, a carefully crafted language for working with graphs

Page 21: Walkthrough Neo4j 1.9 & 2.0

Focus on Cypher

• Cypher, a carefully crafted language for working with graphs

• Declarative, friendly, easy to read and write

Page 22: Walkthrough Neo4j 1.9 & 2.0

Focus on Cypher

• Cypher, a carefully crafted language for working with graphs

• Declarative, friendly, easy to read and write

• One language, used everywhere

Page 23: Walkthrough Neo4j 1.9 & 2.0

Focus on Cypher

• Cypher, a carefully crafted language for working with graphs

• Declarative, friendly, easy to read and write

• One language, used everywhere

• REST for management, Java for extensions,

Page 24: Walkthrough Neo4j 1.9 & 2.0

What is new in 2.0?

Page 25: Walkthrough Neo4j 1.9 & 2.0

There will be some sad Danes

"Once you label me,you negate me.”

- Søren Kierkegaard

Page 26: Walkthrough Neo4j 1.9 & 2.0

Introducing Node Labels

name: 'Soren'

Page 27: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

Introducing Node Labels

name: 'Soren'

Page 28: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

Introducing Node Labels

name: 'Soren'

Dane

Page 29: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

Introducing Node Labels

name: 'Soren'

Dane

Page 30: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

Introducing Node Labels

name: 'Soren'

Negated Dane

Page 31: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

Introducing Node Labels

name: 'Soren'

Negated

name: 'Soren'img:

Dane

Page 32: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

• Find nodes by label

Introducing Node Labels

name: 'Soren'

Negated

name: 'Soren'img:

Dane

Page 33: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

• Find nodes by label

• Constrain properties and values

(lightweight, optional schema)

Introducing Node Labels

name: 'Soren'

Negated

name: 'Soren'img:

Dane

Page 34: Walkthrough Neo4j 1.9 & 2.0

• Simply: a label identifies a set of nodes

• Nodes can have multiple labels

• Find nodes by label

• Constrain properties and values

(lightweight, optional schema)

• A simple idea, with powerful applications

Introducing Node Labels

name: 'Soren'

Negated

name: 'Soren'img:

Dane

Page 35: Walkthrough Neo4j 1.9 & 2.0

Find friends who like cheese

MATCH (max:People)-[:FRIENDS]->(cheesy: People),

(cheesy)-[:LIKE]->(cheese:Things)

WHERE max.name = "Max De Marzi"

AND cheese.name = "Cheese"

RETURN cheesy;

Page 36: Walkthrough Neo4j 1.9 & 2.0

Schema Indexing• Indexes for labels, based on a property

• Simple lookups for now

• Unique indexing coming soon

• Full-text, other special indexes in planning

CREATE INDEX ON :People(name)

Page 37: Walkthrough Neo4j 1.9 & 2.0

MERGE operation• a combination of MATCH + CREATE

• replaces CREATE UNIQUE

• attempts to MATCH, with specified properties and labels

• if match fails, new graph data is created

• optional sub-clauses for handling ON CREATE, and ON MATCHMERGE (charlie { name:'Charlie Sheen', age:10 })ON CREATE charlie SET charlie.created = timestamp()RETURN charlie

Page 38: Walkthrough Neo4j 1.9 & 2.0

Transactional Cypher

Page 39: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

Transactional Cypher

Page 40: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

• transaction as RESTful resource

Transactional Cypher

Page 41: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

• transaction as RESTful resource

• issue multiple statements per request

Transactional Cypher

Page 42: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

• transaction as RESTful resource

• issue multiple statements per request

• multiple requests per transaction

Transactional Cypher

Page 43: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

• transaction as RESTful resource

• issue multiple statements per request

• multiple requests per transaction

• compact response format

Transactional Cypher

Page 44: Walkthrough Neo4j 1.9 & 2.0

• begin, commit, or rollback a transaction

• transaction as RESTful resource

• issue multiple statements per request

• multiple requests per transaction

• compact response format

Transactional Cypher

Page 45: Walkthrough Neo4j 1.9 & 2.0

Anything else?

Page 46: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

Page 47: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

• Breaking changes to some APIs (read CHANGES.txt)

Page 48: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

• Breaking changes to some APIs (read CHANGES.txt)

• Migration of "legacy" indexes (stop STARTing)

Page 49: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

• Breaking changes to some APIs (read CHANGES.txt)

• Migration of "legacy" indexes (stop STARTing)

• Mandatory transactions for all DB interactions

Page 50: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

• Breaking changes to some APIs (read CHANGES.txt)

• Migration of "legacy" indexes (stop STARTing)

• Mandatory transactions for all DB interactions

• Improving installers (in progress)

Page 51: Walkthrough Neo4j 1.9 & 2.0

Anything else?• Performance improvements

• Breaking changes to some APIs (read CHANGES.txt)

• Migration of "legacy" indexes (stop STARTing)

• Mandatory transactions for all DB interactions

• Improving installers (in progress)

• Changing everything to be "all Cypher, all the time"

Page 52: Walkthrough Neo4j 1.9 & 2.0

How to use labels?

Page 53: Walkthrough Neo4j 1.9 & 2.0

Label - special nodes

• replace built-in reference node, with domain specific reference nodes

42

Page 54: Walkthrough Neo4j 1.9 & 2.0

Label - special nodes

• replace built-in reference node, with domain specific reference nodes

42Answer

Page 55: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb

Page 56: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb• Use a label to make queries easier to read & write

Page 57: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb• Use a label to make queries easier to read & write

• And to improve performance through indexing

Page 58: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb• Use a label to make queries easier to read & write

• And to improve performance through indexing

Page 59: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb• Use a label to make queries easier to read & write

• And to improve performance through indexing

• Start with anything you might've put in a legacy index

Page 60: Walkthrough Neo4j 1.9 & 2.0

Labels - rules of thumb• Use a label to make queries easier to read & write

• And to improve performance through indexing

• Start with anything you might've put in a legacy index

• Use lightly, as few labels as needed

Page 61: Walkthrough Neo4j 1.9 & 2.0

Hands-On Cypher

• Migrate Cineasts dataset to use Labels

• Show MATCH on Labels and Properties (+ profile)

• Add an Index on :Person(name) :Movie(title)

• Show MATCH on Labels and Properties (+ profile)

• Show MERGE

Page 62: Walkthrough Neo4j 1.9 & 2.0

Hands-On 2.0• Show Transactional HTTP-Endpoint

• POST initial statements, look at result, check currently running tx in server-info

• POST another create statement to the tx

• POST a new read statement to a new tx that shows isolation

• DELETE second transaction

• POST to COMMIT resource

Page 63: Walkthrough Neo4j 1.9 & 2.0

Is that it for 2.0?

Page 64: Walkthrough Neo4j 1.9 & 2.0

Well, there is this...

Page 65: Walkthrough Neo4j 1.9 & 2.0

Googlehttp://localhost:7474/

Neo4j

LoadTransactions

Neo4j2.0.0

Active Queries 12Master

/var/neo4j/webui.graphdb Active Queries 12

MATCH (n)-[:FRIEND]->(friends) WHERE n.name = 'Andreas'Create a blank node

CREATE (n);

Clear all

MATCH (n)-[r?]->(m)DELETE n,r,m;

ad-hoc query

Relate People

MATCH (from),(to) WHERE n.name = {from}AND to.name = {to}CREATE (from)-[:FRIEND]->(to);

Delia

Andreas

m

People

CREATE (n);

Andreas

Name

Metaphysical

Mood

Delia Excited

Friends by name

CREATE (n);

Andreas

From

Delia

To

Delia Tiberius

Mood survey

CREATE (n);

Andreas

Name

Metaphysical

Mood

Delia ExcitedMATCH (n) RETURN n

People Books ClassicsAuthors

CREATE (me:People {name:'Andreas'})

Page 66: Walkthrough Neo4j 1.9 & 2.0

What is new in 2.0?

Page 67: Walkthrough Neo4j 1.9 & 2.0

What is new in 2.0?

• It's all about Cypher, starting with

• Labels, the first significant change in over 12 years

• Mix in schema indexing

• Then transactional REST, new clauses, functions

• A fresh Web UI that is Cypher-focused

Page 68: Walkthrough Neo4j 1.9 & 2.0

Thanks :)

MATCH (you)-[:HAVE]->(question)RETURN question.text

@neo4j or @mesirii to keep in touch