Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Neo4j strange hanging relationship delete



I am trying to delete all the relationships of a certain type from my database. At first it was working fine with the following code

CALL apoc.periodic.iterate(
'MATCH ()-[r:REL]->() RETURN id(r) AS id', 
'MATCH ()-[r:REL]->() WHERE id(r)=id DELETE r', 
{batchSize: 5000, parallel:true});

But now nothing seems to be working and when I do

MATCH ()-[r:REL]-() return count(r)

I always get roughly 200k back.
If I try to do something like

MATCH ()-[r:REL}-() return id(r) limit 1


MATCH p=()-[r:REL}-() return p limit 1

The query just hangs indefinitely until I terminate it. Anyway to troubleshoot this?

I am on 4.4.0 Enterprise


Graph Fellow


I don't know if this is your case but, as said here apoc.periodic.iterate - APOC Documentation :

For more complex operations like updating or removing relationships,
either do not use parallel: true
OR make sure that you batch the work in a way that each subgraph of data is updated in one operation,
such as by transferring the root objects.
If you attempt complex operations, also enable retrying failed operations, e.g. with retries:3.

If this doesn't work, is there anything useful in errorMessages column of apoc.periodic.iterate result and / or in neo4j.log / debug.log files?

@giuseppe.villani I'm on Neo4j Aura so don't have access to neo4j.log unfortunately.

I did manage to get it working by removing the direction on the query. Interesting adding a -> over a - slowed it down. Not sure if you have insight into this.