Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Neo4j & Cypher: Cleaning Out Your Graph

DZone's Guide to

Neo4j & Cypher: Cleaning Out Your Graph

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

If you want to delete lots of data from a Neo4j database with Cypher:

Just stop the server and delete the directory and start again

Fastest way with no leftovers, just delete db/data/graph.db and you’re done.

Cypher Statement before 2.1

“Unknown Error” or OutOfMemoryException is a symptom that your transaction size gets too big and consumes too much memory.

That is unrelated to your config, you just have to keep it in check.

If you want to delete elements in a batched way use something like this:

MATCH (a)
WITH a
LIMIT 10000
OPTIONAL MATCH (a)-[r]-()
DELETE a,r
RETURN COUNT(*)


Run until the result stays 0. This query will find at most 10000 nodes then find all their rels and then delete both. But how would you do it in Neo4j 2.1 ?

Cypher 2.1 and beyond

You can make use of the new PERIODIC COMMIT feature that takes care of batching behind the scenes. Try this:

USING PERIODIC COMMIT
MATCH (a)
OPTIONAL MATCH (a)-[r]-()
DELETE a,r;



Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
java ,nosql ,tips and tricks ,neo4j ,cypher ,tools & methods

Published at DZone with permission of Michael Hunger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}