22

I need to delete all relationships between all nodes. Is there any way to delete all relationships in the neo4j graph? Note that I am using ruby bindings - the neography gem. There is no info about that in the wiki of the gem. I've also tried to find a way to do it in the neo4j documentation without any result.

Neo4j version is 1.7.2.

roman
  • 5,100
  • 14
  • 44
  • 77

2 Answers2

26

in cypher:

deleting all relationships:

start r=relationship(*) delete r;

creating all relationships between all nodes, i'd assume:

start n=node(*),m=node(*) create unique n-[r:RELTYPE]-m;

but you rather dont want to have too many vertices, since it collapse on low memory (at least in my case i got 1mil vertices and 1gb ram)

ulkas
  • 5,748
  • 5
  • 33
  • 47
  • I've tried to do it the way you suggest but it gives the following message: `Neography::NeographyError: expected return clause.` when trying to delete all relationships. – roman Oct 16 '12 at 12:28
  • you are probably using some extended programming module which cause the trouble. have you tried this in pure cypher console via the admin interface? please paste the problematic part of your ruby code – ulkas Oct 17 '12 at 12:17
  • How to do this through Java core API?? – prasanth Jul 24 '14 at 05:09
  • 1
    @prasanth i dunno, i suggest to create a completely new question – ulkas Jul 24 '14 at 07:43
15

In cypher3.5, start is deprecated.

You can use this cypher to delete all relationships

match ()-[r]->() delete r;
DachuanZhao
  • 1,181
  • 3
  • 15
  • 34
  • 1
    I created the movie graph on the neo4j sandbox. I wanted to delete everything. But to delete the nodes the relationships must first be deleted. This worked perfectly. – Timothy Lombard Jan 13 '20 at 04:39
  • In my use-case, this query is very slow, I suppose it first tries to retrieve all the relationships, then deletes them. If so, I guess a better approach would be to delete without first finding/retrieving relationships. – Dr. Strangelove Jul 01 '22 at 16:27