Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete large amount of nodes in cypher

Tags:

neo4j

cypher

I'm trying to delete 1 million nodes in cyphper at one query using web admin(i.e localhost:7474/browser).
These nodes is labeled as User. I ran following query, then returned Unknown error after waiting about 1minutes.

match (u:User) delete u

This query returned Unknown error every time. and I confirm my PC resources didn't lack. I'm using Neo4j version 2.0.0 RC1 community edition. and Neo4j Hosted on local.
Is My trying way for deletion nodes wrong?
Thanks

like image 398
Michael Avatar asked Sep 13 '25 10:09

Michael


2 Answers

You should do write operations with a reasonable transaction size of ~10-50k atomic operations. Therefore you can use limit and run the statement until all users are gone:

match (u:User) with u limit 1000 delete u
like image 158
Stefan Armbruster Avatar answered Sep 16 '25 12:09

Stefan Armbruster


With Neo4j 3.x and forward you can run large delete transactions using APOC too:

call apoc.periodic.iterate("MATCH (u:User) return u", "DETACH DELETE u", {batchSize:1000})
yield batches, total return batches, total
like image 28
ThirstForKnowledge Avatar answered Sep 16 '25 13:09

ThirstForKnowledge