java - java中的Neo4j Cypher match()。查找连接的节点

标签 java neo4j cypher

我有以下结构

        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 " );

第一个节点通过关系“电子邮件”链接到第二个和第三个节点。类似地,第二个节点连接到第三、第四、第一。

我想要每个节点输出类似这样的内容: secondaryNode=[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 "}

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

最佳答案

  • 您的标签应类似于 :Person not :A, :B, :C
  • 您希望通过第一个节点进行聚合。
  • 您应该使用大写重新输入

尝试这样的事情:

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

关于java - java中的Neo4j Cypher match()。查找连接的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34677104/

相关文章:

java - 这段代码哪里发生了死锁? java

java - Java中匿名类的序列化

javascript - 如何仅通过 Javascript 访问我的 GrapheneDB neo4j 数据库

java - Spring Data Neo4j 父子过滤

java - neo4j - 与 java 建立独特的关系

java - 如何使用 Maven 创建一个 jar,其中包含每个依赖项的单独文件夹中的依赖项

java - 审核/记录所有传入的 Web 请求到 @RequestMapping 带注释的方法

regex - 在 Cypher 查询中使用正则表达式捕获组

node.js - nodejs neo4j 不访问参数 req.params.x 但接受任何硬编码值

neo4j - Neo4j 中的多行执行