2016-09-14 87 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