Showing results for 
Search instead for 
Did you mean: 

Soft Delete of NodeEntity using SDN (Spring data Neo4j)

I have just started with Neo4j Graph implementation for a project. I have use case where I cannot keep the same Node Entity on a daily basis for example

I have Travel as main node and Trip as child node.

Every Travel Node is created with List of Trip, and this activity happens on daily basis.

Before end of each day the Trip needs to removed and archived and next day new set of trips are created.

I want to keep the Old trips for analytics and cannot delete them.

What is the best practices to achieve this ?

Should I have another store where I should move the historical trips or is there something that I can manage in Neo4J.

Any guidance on this regard would be of great help.

Michael Hunger suggested the below, but Not sure how to do it via spring data.

You could for instance relabel them, i.e. add an :Old label or even replace the label with :OldTrip so they are still around but will not be picked up anymore by your queries.



I would like to know if it would make sense to keep the relationships to the travel, not necessary in your Java model but in the graph?

A pragmatic solution that comes to my mind would be something like having a ArchivedTrip class that has all the field you need for the analysis and provide some kind of copy method in place.

public class ArchivedTrip {
 // id, fields, constructors, getter, setters

 ArchivedTrip of(Trip trip) {
   return new ArchivedTrip(trip.getName()....);

Save the newly created ArchiveTrips and remove the Trips afterwards from the Travel.
Important would be to not copy the ids blindly over but create or let the database create new ones. Otherwise you could accedentially override data.

Hi Gerrit Meier,

Thank you for your response. Sounds good.
Will this be a a good practice for large data sets for example if ArchivedTrip
grows to few millions. Will this cause any performance issues.


It will definitely not be a good idea to fetch all ArchivedTrips with any O(G/R/*)M at once when a certain, something in the thousands, amount is reached.
But for Neo4j it is not a big deal to store this number of nodes.