はじめに
Neo4jで色々とデータをためていると
- ノード数200000
- リレーションはそれ以上
みたいな大量のデータになることがあります。
また、さらに使用環境が貧弱だと一括削除のコマンド
match(n) detach delete n
が使用できないことがあります。
There is not enough memory to perform the current task. Please try increasing 'dbms.memory.heap.max_size' in the neo4j configuration (normally in 'conf/neo4j.conf' or, if you you are using Neo4j Desktop, found through the user interface) or if you are running an embedded installation increase the heap by using '-Xmx' command line flag, and then restart the database.
そのため、一部ずつ削除していく必要があります。
対処法
match(n) with n limit 2000 detach delete n;
まず、match(n)で全部のノードを取り出します。
次に2000個にしぼりたいので、別のクエリーにデータを渡すwith句を使用します。
そして、n limit 2000で$2000$個のみに絞りこみ
最後にdetach delete n;で$2000$個を削除できます。