【问题标题】:Neo4j Cypher match () in java. Find connected nodesJava 中的 Neo4j Cypher 匹配()。查找连接的节点
【发布时间】:2016-01-08 12:24:40
【问题描述】:

我有以下结构

        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 "}

我对密码很陌生。如何为此编写匹配语句?这可能吗?

【问题讨论】:

  • 不要使用graphDb.execute创建新的执行引擎!!

标签: java neo4j cypher


【解决方案1】:
  • 您的标签应该类似于:Person not :A、:B、:C
  • 您希望按第一个节点进行聚合。
  • 您应该使用大写重新输入

试试这样的:

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

【讨论】:

  • 谢谢。完美的!有效。但我没有指明方向。
  • 我基于此提出了一个后续问题。你能检查一下吗? link
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多