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
MATCH (r)-[create_process_to]->()
WHERE NOT r.image = "wsmpro.exe"
DETACH DELETE r
But it does not work since the above figure become the below
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.
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