2016-09-14 93 views
0

我正在使用HTTP API(以及用於測試的Web界面)與Neo4j進行交互。我想繪製一個關係圖,但我無法確定關係數據在事務響應中的位置,因爲relationship數組都是空的。關係數據顯然存在,因爲Web界面正在從這些數據繪製關係圖。關係數據在哪裏?

例如,當我運行查詢match (n) return (n),網絡接口提供了以下的響應數據(這是從設置有Neo4j的樣本影片集):

{ 
    "results": [ 
    { 
     "columns": [ 
     "n" 
     ], 
     "data": [ 
     { 
      "row": [ 
      { 
       "tagline": "Welcome to the Real World", 
       "title": "The Matrix", 
       "released": 1999 
      } 
      ], 
      "meta": [ 
      { 
       "id": 181, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "181", 
       "labels": [ 
        "Movie" 
       ], 
       "properties": { 
        "tagline": "Welcome to the Real World", 
        "title": "The Matrix", 
        "released": 1999 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1964, 
       "name": "Keanu Reeves" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 182, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "182", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1964, 
        "name": "Keanu Reeves" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1967, 
       "name": "Carrie-Anne Moss" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 183, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "183", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1967, 
        "name": "Carrie-Anne Moss" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1961, 
       "name": "Laurence Fishburne" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 184, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "184", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1961, 
        "name": "Laurence Fishburne" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1960, 
       "name": "Hugo Weaving" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 185, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "185", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1960, 
        "name": "Hugo Weaving" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1967, 
       "name": "Andy Wachowski" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 186, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "186", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1967, 
        "name": "Andy Wachowski" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1965, 
       "name": "Lana Wachowski" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 187, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "187", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1965, 
        "name": "Lana Wachowski" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1952, 
       "name": "Joel Silver" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 188, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "188", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1952, 
        "name": "Joel Silver" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1978, 
       "name": "Emil Eifrem" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 189, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "189", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1978, 
        "name": "Emil Eifrem" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "tagline": "Free your mind", 
       "title": "The Matrix Reloaded", 
       "released": 2003 
      } 
      ], 
      "meta": [ 
      { 
       "id": 190, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "190", 
       "labels": [ 
        "Movie" 
       ], 
       "properties": { 
        "tagline": "Free your mind", 
        "title": "The Matrix Reloaded", 
        "released": 2003 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "tagline": "Everything that has a beginning has an end", 
       "title": "The Matrix Revolutions", 
       "released": 2003 
      } 
      ], 
      "meta": [ 
      { 
       "id": 191, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "191", 
       "labels": [ 
        "Movie" 
       ], 
       "properties": { 
        "tagline": "Everything that has a beginning has an end", 
        "title": "The Matrix Revolutions", 
        "released": 2003 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "tagline": "Evil has its winning ways", 
       "title": "The Devil's Advocate", 
       "released": 1997 
      } 
      ], 
      "meta": [ 
      { 
       "id": 192, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "192", 
       "labels": [ 
        "Movie" 
       ], 
       "properties": { 
        "tagline": "Evil has its winning ways", 
        "title": "The Devil's Advocate", 
        "released": 1997 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1975, 
       "name": "Charlize Theron" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 193, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "193", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1975, 
        "name": "Charlize Theron" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1940, 
       "name": "Al Pacino" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 194, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "194", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1940, 
        "name": "Al Pacino" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1944, 
       "name": "Taylor Hackford" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 195, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "195", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1944, 
        "name": "Taylor Hackford" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "tagline": "In the heart of the nation's capital, in a courthouse of the U.S. government, one man will stop at nothing to keep his honor, and one will stop at nothing to find the truth.", 
       "title": "A Few Good Men", 
       "released": 1992 
      } 
      ], 
      "meta": [ 
      { 
       "id": 196, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "196", 
       "labels": [ 
        "Movie" 
       ], 
       "properties": { 
        "tagline": "In the heart of the nation's capital, in a courthouse of the U.S. government, one man will stop at nothing to keep his honor, and one will stop at nothing to find the truth.", 
        "title": "A Few Good Men", 
        "released": 1992 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "born": 1962, 
       "name": "Tom Cruise" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 197, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "197", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "born": 1962, 
        "name": "Tom Cruise" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
[...cropped...] 
     { 
      "row": [ 
      { 
       "name": "Jessica Thompson" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 350, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "350", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "name": "Jessica Thompson" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     }, 
     { 
      "row": [ 
      { 
       "name": "James Thompson" 
      } 
      ], 
      "meta": [ 
      { 
       "id": 351, 
       "type": "node", 
       "deleted": false 
      } 
      ], 
      "graph": { 
      "nodes": [ 
       { 
       "id": "351", 
       "labels": [ 
        "Person" 
       ], 
       "properties": { 
        "name": "James Thompson" 
       } 
       } 
      ], 
      "relationships": [] 
      } 
     } 
     ], 
     "stats": { 
     "contains_updates": false, 
     "nodes_created": 0, 
     "nodes_deleted": 0, 
     "properties_set": 0, 
     "relationships_created": 0, 
     "relationship_deleted": 0, 
     "labels_added": 0, 
     "labels_removed": 0, 
     "indexes_added": 0, 
     "indexes_removed": 0, 
     "constraints_added": 0, 
     "constraints_removed": 0 
     } 
    } 
    ], 
    "errors": [], 
    "responseTime": 225 
} 

我看不到的關係數據的任何地方在這裏,所有的relationship數組都是空的?然而,不知何故,網絡界面設法從這些數據中繪製出這個圖表: enter image description here

我很明顯缺少關於如何從neo4j響應中提取關係數據的關鍵問題。

回答

2

您的查詢不會別名或返回任何關係。前端顯示它們是因爲它顯示了它顯示的節點之間存在的任何關係。讓你的查詢有點像MATCH() - [r] -() RETURN r,你會看到一些關係數據顯示。

編輯:您的RETURN語句確定從API返回的數據。如果您不要求它返回任何關係,則HTTP響應將不包含它們,但瀏覽器視圖將智能地顯示關係。不過,您可以返回關係,但返回節點的方式相同:使用模式爲其分配別名,然後返回別名。

+2

右下角的「自動完成」開關打開和關閉此行爲。 如果您禁用自動完成功能,Neo4J瀏覽器將顯示準確返回的查詢。 – adekcz