问题
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