What is the best way to model removal of a relationship using Java API?

16 views
Skip to first unread message

Nirmalya Sengupta

unread,
Sep 16, 2015, 8:13:51 PM9/16/15
to Neo4j
Hello all,

I am trying to understand how to model use-cases which require removal of a Relationship between two nodes.

Let's say that, we are capturing the current destination of a ship to a port.

<ship1> --- MovingTowards --> <port1>

After some time, ship1 reaches port1, unloads cargo, loads new cargo and then sails for port2. The latest snapshot of the Graph should indicate that clearly.

To capture this correctly, I think I should remove the current relationship between ship1 and port1 and add a new relationship between ship1 and port2

<ship1> --- Moving 'X' Towards --> <port1>, and
<ship1> --- MovingTowards --> <port2>

How do I achieve this using Java APIs? Is this even the right approach? If now, what should be?

-- Nirmalya


Peter Hunsberger

unread,
Sep 16, 2015, 9:17:14 PM9/16/15
to ne...@googlegroups.com
Once a relationship is deleted then you have no historical reporting capabilities unless you'r managing that somewhere else....

I don't know about your use case but typically these kinds of relationships have a time frame associated with them.  Given that a ship may in fact be moving away from it's destination at a minimum I'd use a Destination relationship with departure date and arrival date attributes on the Destination relationship.  However, if you ever want to report on  trips between certain time periods then the dates might become first class nodes.  In that case you might want to introduce trips as first class nodes and have them liked to destinations and departure and arrival dates

<ship1> --  Traveled --> <trip1> -- Destination --> <port1>
.......................................+ -- Departure--> <date1>
.......................................+ -- Arrival --> <date2>

You have to watch out for dates becoming super nodes but this is very generally useful.  You can then also start to collect things like "scheduled arrival" on the trip or break the trip into segments or legs each with their own set of dates etc.

Peter Hunsberger

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nirmalya Sengupta

unread,
Sep 17, 2015, 1:28:54 AM9/17/15
to Neo4j
Hello Peter,

Many thanks for detailed reply. Great points on the importance of the temporal nature of the relationship. You are right: my Use-Case indeed has a time-aspect and I need to capture them in some manner. I didn't mention them because I wanted to keep the query, simple.

My question was driven by my concern of about growing size of the Graph. Indeed, if a relationship has served it purpose and we are unlikely to use it ever again, we may want to remove it, may we not? We want to prune the Graph of unnecessary relations. If that is so, how does one do that in Neo4j using Java APIs (I have seen examples of achieving the same using Cypher but at the moment, our software is primarily using Java APIs)?

Will appreciate your views on this.

-- Nirmalya

Peter Hunsberger

unread,
Sep 17, 2015, 8:51:26 AM9/17/15
to ne...@googlegroups.com
Get the model correct 1st.  Worry about optimizing it last....

Peter Hunsberger

Nirmalya Sengupta

unread,
Sep 17, 2015, 10:37:29 AM9/17/15
to ne...@googlegroups.com
Alright. Point taken. Thanks.

-- N

--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/Qi6duNMF7gk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Software Technologist
http://www.linkedin.com/in/nirmalyasengupta
"If you have built castles in the air, your work need not be lost. That is where they should be.
Now put the foundation under them."
Reply all
Reply to author
Forward
0 new messages