Delete old nodes and relationships with Cypher in Neo4j 1.9

二次信任 提交于 2019-12-11 04:18:10

问题


I am using Neo4j 1.9 M03 in HA mode, my challenge is to remove all nodes and relationships as well as indices that are older than a certain date.

For this I created a property for nodes and relationships. The property is a datestamp in the "YYMMDD" format.

I'm trying to use the following Cypher query to perform the operation mentioned above:

START n0=node(0), nx=node(*) 
MATCH n0-[r0?]-(), nx-[rx?]-() 
WHERE nx <> n0 AND HAS (nx.datestamp) AND nx.datestamp <= yyyymmdd 
OR HAS (rx.datestamp) AND rx.datestamp <= yyyymmdd
DELETE r0,rx,nx

This query is not performing the operation I desire. What can I be doing wrong here?


回答1:


START rx=rel(*)
WHERE HAS (rx.datestamp) AND rx.datestamp <= yyyymmdd
DELETE rx;

You have to make sure that the nodes you want to delete don't have any relationships left, either filter those out or you delete those additionally

START nx=node(*)
WHERE HAS (nx.datestamp) AND nx.datestamp <= yyyymmdd
AND NOT((nx)--())
DELETE nx;



回答2:


You can try this one

START n=node(*) 
MATCH n-[r?]-() 
WHERE  (n.datestamp? <= yyyymmdd AND r.datestamp? <= yyyymmdd) 
DELETE r,n


来源:https://stackoverflow.com/questions/17034105/delete-old-nodes-and-relationships-with-cypher-in-neo4j-1-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!