Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-14-2022 12:42 AM - edited 11-14-2022 12:48 AM
The Figure show below
Orange Node only three : cmd.exe, ipconfig.exe, wsmpro.exe (All of them are "Process" node)
Orange relation : create_process_to
I want to delete all the node and relation if the node that linked each others by create_process_to do not involved the "wsmpro.exe" node. That is, the result should be the following
Since others do not involved wsmpro.exe node. I tried
which is not what I want.
How can I do? Thanks.
Solved! Go to Solution.
11-14-2022 08:43 AM
Try this.
match (p:Process{image:"wsmpro.exe"})
match path=(p)-[*]-()
unwind nodes(path) as node
with collect(distinct id(node)) as nodeIdsToKeep
match(n:Process)
where not id(n) in nodeIdsToKeep
detach delete n
11-14-2022 01:43 AM - edited 11-14-2022 01:45 AM
MATCH (r)
WHERE NOT r.image = "wsmpro.exe"
OPTIONAL MATCH (r)-[relation:create_process_to]->()
DELETE r,relation
11-14-2022 08:13 AM
I tried What you said, but the following shows
Cannot delete node<896>, because it still has relationships
If I add DETACH, then all the node and edge just disappear.
11-14-2022 04:39 AM - edited 11-14-2022 04:42 AM
It is a little more complicated, since what you want is to keep all nodes of each subgraph anchored on each wspro.exe node. I think what you need to do is 1) match on all wsmpro.exe nodes, 2) expand on each to get each node’s subgraph of nodes, 3) get the list of node ids from all the nodes across each subgraph, 4) match all nodes whose node id is not in the set of node id’s just derived, and 5) detach delete each of the nodes matched.
If you confirm my understanding is correct, I can write a query if you need help.
11-14-2022 08:15 AM
Yes you're correct, that is the method which I have thought earlier but I can not get the result correctly since I'm not very familiar with Cypher.
It would be a big help if you could give me a help, thanks!
11-14-2022 08:43 AM
Try this.
match (p:Process{image:"wsmpro.exe"})
match path=(p)-[*]-()
unwind nodes(path) as node
with collect(distinct id(node)) as nodeIdsToKeep
match(n:Process)
where not id(n) in nodeIdsToKeep
detach delete n
11-14-2022 11:55 PM
Appreciate, this idea gives me a biggggg help (not only in this case)!
All the sessions of the conference are now available online