2
votes

How should I get all the existing relationships between each two nodes in a graph in neo4j by java?

I want the results which this cypher query returns:

start r=rel(*) return r 

so later I can change or delete some of them based on my conditions?

or get the start or end node of them.

this is what I have done so far:

Iterable<Relationship> rels=GlobalGraphOperations.at(db).getAllRelationships();
  for (Relationship rel: rels )
  {} 

but I have error in this line:for (Relationship rel: rels )

the error is because does not know rels ,and wants to create a class for it.

1

1 Answers

2
votes

I used this for indexing and it was working:

  GlobalGraphOperations ggo = GlobalGraphOperations.at(db);

  for (Relationship r : ggo.getAllRelationships()) {
       //indexing code
    }

try to get relationships on single node and check result e.g.

Iterable<BatchRelationship>  _itlRelationship= _neo.getRelationships(_empNodeId);

            Iterator<BatchRelationship> _itRelationship= _itlRelationship.iterator();

            while (_itRelationship.hasNext()) {}