how to change relationship property value?

1,042 views
Skip to first unread message

tAds

unread,
Aug 3, 2012, 1:10:11 AM8/3/12
to ne...@googlegroups.com
hello, 
           I have 2 nodes that are related to each other.This relationship has a property called weightage with a value' 70 '. I want to increase the value. To do so, I want to retrieve the value of the property (wightage=70)  between these two nodes.I can retrieve these two nodes.From the nodes, how can i get the relationship and then the property of that relationship?

Thanks in advance. :)  

Peter Neubauer

unread,
Aug 3, 2012, 1:58:57 AM8/3/12
to ne...@googlegroups.com

Start a=node(2),b=node(3) match a- [r]-b set r.weightage=70 return r

/peter

Send from mobile.

Message has been deleted

dizus

unread,
Aug 3, 2012, 2:09:01 AM8/3/12
to ne...@googlegroups.com
http://api.neo4j.org/1.8.M06 - Look for class Node and methods family: getRelationships().

You dont need to retrieve both nodes as you can get relationships from any node (it's just a matter of relationship direction),
so basicly you do:

for( Relationship rel: node.getRelationships(Direction.OUTGOING, YourRelationTypeHere) ) {  
    double w = (Double) rel.getProperty("weightage");
    if( w == 70 ) {
        w += 123.45;
       rel.setProperty("weightage", w)
    }
}

Keep in mind that node may have multiple relationship (depends on your application logic), so probably
you need to do some additional filtering.

Charles Bedon

unread,
Aug 3, 2012, 9:17:39 AM8/3/12
to ne...@googlegroups.com
Hello

There are many ways to get a relationship from one of the related nodes:

http://api.neo4j.org/1.8.M06/org/neo4j/graphdb/Node.html#getSingleRelationship%28org.neo4j.graphdb.RelationshipType,%20org.neo4j.graphdb.Direction%29

That will return a Relationship object, and from it, you can get the relationship property values:

http://api.neo4j.org/1.8.M06/org/neo4j/graphdb/Relationship.html
http://api.neo4j.org/1.8.M06/org/neo4j/graphdb/PropertyContainer.html#getProperty(java.lang.String)


By the way, the Javadoc link for the 1.7.2/1.6.3 APIs is broken:
http://api.neo4j.org/1.7.2/
http://api.neo4j.org/1.6.3/
-------------------------------------
Charles Edward Bedón Cortázar
Network Management, Data Analysis and Free Software http://www.neotropic.co | Follow Neotropic on Twitter
Open Source Network Inventory for the masses!  http://kuwaiba.sourceforge.net | Follow Kuwaiba on Twitter
Linux Registered User #386666


---- Am Fri, 03 Aug 2012 00:10:11 -0500 tAds<shrt...@gmail.com> schrieb ----
Reply all
Reply to author
Forward
0 new messages