现在我有一个这样的图:
然后我要查询“ SGJ”“ HAVE”的节点
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
RETURN k
但是我得到这样的结果:
{
"id": 360,
"children": null,
"name": "Arrays",
"intro": "this is an intro"
},
{
"id": 300,
"children": null,
"name": "Java",
"intro": "this is an intro"
}
这些节点之间的关系刚刚消失,希望我可以查询与该关系保持一致的节点:
{
"id": 360,
"children": [
{
"id": 300,
"children": null,
"name": "Java",
"intro": "this is an intro"
}
],
"name": "Arrays",
"intro": "this is an intro"
}
这是实体定义:
@Data
@NodeEntity
public class KNode {
@GraphId
Long id;
@Relationship(type = "BELONGS_TO", direction = Relationship.INCOMING)
List<KNode> children;
private String name;
private String intro;
}
有什么解决办法吗?谢谢。
答案 0 :(得分:0)
您只是返回一个节点而不是路径。尝试以下请求之一以返回孩子和亲戚:
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
OPIONAL MATCH p=(k)-[r]-(c)
RETURN p
或:
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
WITH k
MATCH p=(k)-[r]-(c)
RETURN p