簡體   English   中英

如何查詢Neo4j節點及其之間的關系?

[英]How to query Neo4j nodes and the relationship between the nodes?

現在我有一個像這樣的圖:

樣本圖

然后我要查詢“ 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;

}

有什么解決辦法嗎? 謝謝。

您只是返回一個節點而不是路徑。 請嘗試以下請求之一以返回孩子和親戚:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM