Here's how you execute cypher queries from Java.
Here's some code for how you'd get those relationships. I haven't tested this, but it's the right general approach.
String query = "MATCH (n:Phone{id:'you'}) MATCH n-[r:calling]->m WHERE n<>m RETURN n, r, m";
ExecutionEngine engine = new ExecutionEngine( db );
ExecutionResult result;
try ( Transaction ignored = db.beginTx() ) {
result = engine.execute(query);
ResourceIterator<Relationship> rels = result.columnAs("r");
while(rels.hasNext()) {
Relationship r = rels.next();
// Do something cool here.
}
} catch(Exception exc) { System.err.println("ERHMAGEHRD!!!"); }
Basically, use the columnAs()
method to get a result column. Note that here it's "r" because your query is returning relationships into a variable that name.
OK, now for your question about the query. In java, I like to return as little as possible from queries. If you need it, it should be in the return clause. If you don't, then it shouldn't be.
If you want the relationships, then return them. Don't try to get at relationships by returning the nodes, then looking from there. That approach will work, but just going straight for the relationships makes more sense.