简体   繁体   中英

Neo4j delete graph big data

I have a huge file of for about 11M relationship . When I run the query : Match (n) detach delete n , It seems to be taking forever to finish . I did some researches and found that I need to delete the relationships with a limit and then the nodes using that query :

MATCH (n)
 OPTIONAL MATCH (n)-[r]-()
 WITH r LIMIT 200000
 DELETE r
 RETURN count(r) as deletedCount

Yet, and as I'm doing some performances comparison , it dows not seem logic to me to sum the total of deletion time to delete the hole graph . and as it changes when changing the limit value of relationships to delete at once. (if i do 2000 relationships it is not the same as 20000 relationships at once)

How can I solve that problem ? Any help would be appreciated

You can use apoc.periodic.commit to help you with batching. You must use apoc plugin , which has lots of cool functions to enhance cypher.

You can use the following cypher query.

call apoc.periodic.commit("
match (node)
with node limit {limit}
DETACH DELETE node
RETURN count(*)
",{limit:10000})

This will run the query in batches until the first match return null, which means in this case that no node exists in the database. You can play around with different limit settings to see what works best.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM