簡體   English   中英

Neo4j Java中的Cypher match()。 查找連接的節點

[英]Neo4j Cypher match () in java. Find connected nodes

我有下面的結構

        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通過關系“電子郵件”鏈接到第二和第三。 類似地,第二節點連接到第三,第四,第一。

我想為每個節點輸出類似這樣的內容: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很陌生。 如何為此編寫匹配語句? 這可能嗎?

  • 您的標簽應類似於:Person而不是:A,:B,:C
  • 您想按第一個節點進行聚合。
  • 您應該使用大寫重新輸入

嘗試這樣的事情:

MATCH (sender:Person)-[:EMAILS]->(receiver) 
RETURN sender,collect(receiver) as receivers

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM