关系数据在哪里?

时间:2016-09-14 21:57:07

标签: neo4j

我正在使用HTTP API(以及用于测试的Web界面)与Neo4j进行交互。我想绘制一个关系图,但我无法弄清楚关系数据在事务响应中的位置,因为relationship数组都是空的。关系数据显然存在于某处,因为Web界面正在从这些数据中绘制关系图。

例如,当我运行查询match (n) return (n)时,Web界面会提供以下响应数据(这是来自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数组都是空的?然而,不知何故,Web界面设法从这些数据中绘制这个图: enter image description here

我显然遗漏了一些关于如何从neo4j响应中提取关系数据的批评。

1 个答案:

答案 0 :(得分:2)

您的查询没有别名或返回任何关系。前端显示它们,因为它显示它显示的节点之间存在的任何关系。使您的查询类似于MATCH () - [r] - () RETURN r,您会看到一些关系数据显示。

编辑:您的RETURN语句确定从API返回的数据。如果您不要求它返回任何关系,HTTP响应将不会包含它们,但浏览器视图将智能地显示关系。但是,您可以返回一个关系,就像返回节点一样:使用模式为其指定别名,然后返回别名。