Iterating over relationships of a specific type

88 views
Skip to first unread message

vlg

unread,
Apr 30, 2012, 10:28:11 AM4/30/12
to Neo4j
Hi there,

Using Neo4j 1.6.2, what would be the best way to iterate over /
retrieve all the relationships of a specific type ?

I guess I could use an index on a property that would store the name
of the relationship type, but this means extra-storage and extra-
operations upon adding edges, so I was wondering if there were any
built-in method to achieve this.

Thanks,
Vincent

Michael Hunger

unread,
Apr 30, 2012, 10:42:56 AM4/30/12
to ne...@googlegroups.com
As this would be a graph global operation it is not supported as of now, it would be even more expensive to do w/o an index.

Without an index you'd have to:

for (Node n : GlobalGraphOperations.at(gdb).getAllNodes()) {
Relationship rel = n.getRelationships(TYPE,Direction.OUTGOING);
// do something with the relationship
}

or with cypher:

start n=node(*) match n-[r:TYPE]->() return r

see here for an example: http://tinyurl.com/7ewusrs

Michael

Mattias Persson

unread,
May 1, 2012, 5:06:10 AM5/1/12
to ne...@googlegroups.com


2012/4/30 Michael Hunger <michael...@neotechnology.com>

As this would be a graph global operation it is not supported as of now, it would be even more expensive to do w/o an index.

Without an index you'd have to:

for (Node n : GlobalGraphOperations.at(gdb).getAllNodes()) {
   Relationship rel = n.getRelationships(TYPE,Direction.OUTGOING);
   // do something with the relationship
}

Or (this might be faster since it's a linear scan of the relationship store, if all relationships aren't already loaded):

for ( Relationship rel :  GlobalGraphOperations.at(gdb).getAllRelationships() ) {
    if ( rel.isType( myType ) ) {

        // do something with the relationship
    }
}

or with cypher:

start n=node(*) match n-[r:TYPE]->() return r

see here for an example: http://tinyurl.com/7ewusrs

Michael

Am 30.04.2012 um 16:28 schrieb vlg:

> Hi there,
>
> Using Neo4j 1.6.2, what would be the best way to iterate over /
> retrieve all the relationships of a specific type ?
>
> I guess I could use an index on a property that would store the name
> of the relationship type, but this means extra-storage and extra-
> operations upon adding edges, so I was wondering if there were any
> built-in method to achieve this.
>
> Thanks,
> Vincent
>




--
Mattias Persson, [mat...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
Reply all
Reply to author
Forward
0 new messages