[Neo] Checking whether a relationship exists between two nodes...

Rick Bullotta rick.bullotta at burningskysoftware.com
Tue Feb 2 23:47:59 CET 2010

Hi, Maria.

You should be using the hasRelationship(...) method of the Node object.


Best regards,


-----Original Message-----
From: user-bounces at lists.neo4j.org [mailto:user-bounces at lists.neo4j.org] On
Behalf Of Maria Giatsoglou
Sent: Tuesday, February 02, 2010 5:45 PM
To: user at lists.neo4j.org
Subject: [Neo] Checking whether a relationship exists between two nodes...

Hello all

I am creating a project that performs a number of benchmark tasks on Neo.
One of the tests measures the required time for creating a relationship 
between two neo nodes A and B.
However, before creating the relationship, it should firs be checked 
whether a relationship of the same type already exists
between these two nodes. My current implementation calls the 
getRelationships() function
for the A node and then iterates over the returned Iterable object 
checking whether a relationship's end node is equal to node B.  If  such
a relationship does not exist, then the required relationship is created 
between nodes A and B. 

However, this technique seems to be very slow, with the creation of a 
relationship (including the check operation)  taking around 57msec to
complete. Is there a faster way to implement this operation? I 
considered trying to modify the LuceneIndexService implementation in 
order to enable indexing
relationships apart from nodes. Do you recommend such an approach for 
this problem?

Many thanks in advance,
Best regards,

Maria Giatsoglou
Neo mailing list
User at lists.neo4j.org

More information about the User mailing list