[英]How to query Neo4j nodes and the relationship between the nodes?
Now I have a graph like this: 现在我有一个像这样的图:
Then I want to query the nodes which the "SGJ" "HAVE" 然后我要查询“ SGJ”“ HAVE”的节点
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
RETURN k
But I get the result like this: 但是我得到这样的结果:
{
"id": 360,
"children": null,
"name": "Arrays",
"intro": "this is an intro"
},
{
"id": 300,
"children": null,
"name": "Java",
"intro": "this is an intro"
}
The relationship between these nodes just gone, I hope I can query the nodes with the relationship remain like: 这些节点之间的关系刚消失了,希望我可以查询与该关系的节点仍然像:
{
"id": 360,
"children": [
{
"id": 300,
"children": null,
"name": "Java",
"intro": "this is an intro"
}
],
"name": "Arrays",
"intro": "this is an intro"
}
Here's the entity definition: 这是实体定义:
@Data
@NodeEntity
public class KNode {
@GraphId
Long id;
@Relationship(type = "BELONGS_TO", direction = Relationship.INCOMING)
List<KNode> children;
private String name;
private String intro;
}
Is there any solution? 有什么解决办法吗? Thanks.
谢谢。
You are just returning a node instead of path. 您只是返回一个节点而不是路径。 Try one of these requests to return also the children and relationship :
请尝试以下请求之一以返回孩子和亲戚:
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
OPIONAL MATCH p=(k)-[r]-(c)
RETURN p
Or : 要么 :
MATCH (n:User) -[R:MASTER]-> (k:KNode)
WHERE n.username={username}
WITH k
MATCH p=(k)-[r]-(c)
RETURN p
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.