我有以下结构
firstNode = graphDb.createNode();
firstNode.setProperty( "person", "Andy " );
Label myLabel = DynamicLabel.label("A");
firstNode.addLabel(myLabel);
secondNode = graphDb.createNode();
secondNode.setProperty( "person", "Bobby" );
Label myLabel1 = DynamicLabel.label("B");
secondNode.addLabel(myLabel1);
ThirdNode = graphDb.createNode();
ThirdNode.setProperty( "person", "Chris " );
Label myLabel2 = DynamicLabel.label("C");
ThirdNode.addLabel(myLabel2);....
relationship = firstNode.createRelationshipTo( secondNode, RelTypes.emails );
relationship.setProperty( "relationship", "email " );
relationship = firstNode.createRelationshipTo( ThirdNode, RelTypes.emails );
relationship.setProperty( "relationship", "email " );
relationship = secondNode.createRelationshipTo( ThirdNode, RelTypes.emails );
relationship.setProperty( "relationship", "email " );
relationship = secondNode.createRelationshipTo( FourthNode, RelTypes.emails );
relationship.setProperty( "relationship", "email " );
firstNode通过关系“emails”链接到第二个和第三个。类似地,第二节点连接到第三,第四,第一节点。
我希望每个节点输出类似于:secondNode = [firstNode,FouthNode,ThirdNode],firstNode = [second,third],third = ...
我试过这样的事情:
try{
ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult result = engine.execute("MATCH (secondNode{person:'Bobby'})<-[:emails]-(node)RETURN node");
System.out.println(result.dumpToString());
tx1.success();
}
我得到了输出:Node[0]{person:"Andy "}
我对cypher很新。如何为此写匹配语句?这可能吗?
答案 0 :(得分:1)
尝试这样的事情:
MATCH (sender:Person)-[:EMAILS]->(receiver)
RETURN sender,collect(receiver) as receivers