Neo4j Java中的Cypher match().查找连接的节点 [英] Neo4j Cypher match () in java. Find connected nodes

查看:632
本文介绍了Neo4j Java中的Cypher match().查找连接的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的结构

        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通过关系电子邮件"链接到第二和第三.类似地,第二节点连接到第三,第四,第一.

firstNode is linked to second and third by the relation "emails". Similarly, second node is connected to third, fourth, first.

我想要为每个节点输出类似以下内容:secondNode = [firstNode,FouthNode,ThirdNode],firstNode = [second,third],third = ...

I want for each node output somethinglike this: 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很陌生.如何为此编写匹配语句?这可能吗?

Im am very new to cypher. How to write match statement for this? Is this possible?

推荐答案

  • 您的标签应类似于:Person而不是:A,:B,:C
  • 您要按第一个节点进行聚合.
  • 您应该使用大写重新输入
  • 尝试这样的事情:

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

    这篇关于Neo4j Java中的Cypher match().查找连接的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆