Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-28-2022 01:30 AM
hello, I have few graphs in my neo4j and I want to delete one of them that looks like this:
Thank u and have a great day!
Solved! Go to Solution.
05-03-2022 02:25 AM
First, you must install GDS plugin on your database.
Then, you create a graph projection on the whole database:
CALL gds.graph.project(
"graph",
"*",
"*"
)
YIELD graphName AS graph, nodeProjection, nodeCount AS nodes, relationshipProjection, relationshipCount AS rels
Then you run the WCC algorithm in write mode (each subgraph is a component and will have its own componentId
😞
CALL gds.wcc.write('graph', { writeProperty: 'componentId' })
YIELD nodePropertiesWritten, componentCount;
Then you delete the graph projection which is stored in-memory:
CALL gds.graph.drop('graph', false) YIELD graphName;
Finally, you can delete the subgraph based on the componentId
(the query deletes the subgraph which has 0 as componentId
) property stored on nodes (the query works on at least Neo4j 4.4 version):
MATCH (n)
WHERE n.componentId = 0
CALL {
WITH n
DETACH DELETE n
} IN TRANSACTIONS OF 10000 ROWS;
Or this query if you are under Neo4j 4.4 version:
CALl apoc.periodic.iterate(
"MATCH (n) WHERE n.componentId = 0 RETURN n",
"DETACH DELETE n", {batchSize: 10000}
)
YIELD batches, total
RETURN batches, total
Regards,
Cobra
04-28-2022 02:20 AM
Hello @verachkaverachka
I don't understand what is the issue?
Do you want to delete the whole graph or only a subgraph?
Regards,
Cobra
04-28-2022 02:25 AM
I want to delete the whole graph in this image , but in my neo4j database I have other graphs too that I didn't show in this image and I don't want to affect them when I delete this graph
04-28-2022 02:41 AM
A smart way would be to run the Weakly Connected Components algorithm from the GDS plugin on your database. Each subgraph will have its own community, then you will be able to delete all nodes and relationships from a community.
05-01-2022 01:39 AM
Thank you so much for your answers! I haven't tried yet your solutions I Will try them this week and if something won't work i'll let you know 🙂
05-03-2022 02:17 AM
Hey 🙂 i'm trying to understand how to delete this graph without touching any other graphs in my database that doesn't appear in the following picture, and I didn't quite understand how to use this weakly connected Componnent with the GDS plugin, can you elaborate a little more? how will be smart to create a query that will fit me this is the graph i'm trying to delete right now it starts with node named Graph
05-03-2022 02:25 AM
First, you must install GDS plugin on your database.
Then, you create a graph projection on the whole database:
CALL gds.graph.project(
"graph",
"*",
"*"
)
YIELD graphName AS graph, nodeProjection, nodeCount AS nodes, relationshipProjection, relationshipCount AS rels
Then you run the WCC algorithm in write mode (each subgraph is a component and will have its own componentId
😞
CALL gds.wcc.write('graph', { writeProperty: 'componentId' })
YIELD nodePropertiesWritten, componentCount;
Then you delete the graph projection which is stored in-memory:
CALL gds.graph.drop('graph', false) YIELD graphName;
Finally, you can delete the subgraph based on the componentId
(the query deletes the subgraph which has 0 as componentId
) property stored on nodes (the query works on at least Neo4j 4.4 version):
MATCH (n)
WHERE n.componentId = 0
CALL {
WITH n
DETACH DELETE n
} IN TRANSACTIONS OF 10000 ROWS;
Or this query if you are under Neo4j 4.4 version:
CALl apoc.periodic.iterate(
"MATCH (n) WHERE n.componentId = 0 RETURN n",
"DETACH DELETE n", {batchSize: 10000}
)
YIELD batches, total
RETURN batches, total
Regards,
Cobra
05-03-2022 02:29 AM
thank you so much for your detailed answers! i'm going to try it now 🙂 i'll let you know if i've completed it all successfully !
05-03-2022 03:30 AM
Do I have to install apoc if i use version of neo4j that is under 4.4?
05-03-2022 04:07 AM
Yes you have to install APOC.
All the sessions of the conference are now available online