neo4j - Delete all but the top-k nodes of some query -


i try replicate behaviour of following sql query in neo4j

delete history history.name = $modelname , id not in (    select history.id    history    join model on model.id = history.model_id    order created desc    limit 10 ) 

i tried lot of different queries, i'm struggling incorporate finding top-k elements. that's closest got solution.

match (h:history)-[:history]-(m:model) h.name = $modelname h match (t:history)-[:history]-(m:model) t order t.created desc limit 10 not h in t  delete h 

with query error expected list<t> node line with t order t.created desc limit 10.
tried changing it collect(t) t error expected any, map, node or relationship list<node>.

so i'm pretty stuck. idea how write query in cypher?

following approach, should reverse order, matching top-k nodes, collecting them, , performing match nodes matched aren't in collection.

match (t:history)-[:history]-(:model) t order t.created desc limit 10 collect(t) saved  match (h:history)-[:history]-(:model) h.name = $modelname , not h in saved detach delete h 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -