Deleting all nodes and relationships in neo4j using cypher exceeds heap space

后端 未结 6 1603
失恋的感觉
失恋的感觉 2021-02-05 20:50

I have been trying to run this query as recommended in the neo4j google group and in other sources online:

START n = node(*) MATCH n-[r?]-() WHERE ID(n)>0 DELETE n, r;

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 21:12

    According to neo4j documentation, the deletion of a graph isa done through:

    MATCH (n)
    OPTIONAL MATCH (n)-[r]-()
    DELETE n,r;
    

    To avoid the java heap space error, I conbined this code with LIMIT:

    MATCH (n)
    OPTIONAL MATCH (n)-[r]-()
    WITH n,r LIMIT 100000 DELETE n,r;
    

    It works to reduce node number and eventually lets use the first, recomended and more general code.

提交回复
热议问题