Juicy
Juicy

Reputation: 12520

Where is the relationship data?

I'm using the HTTP API (and the web interface for tests) to interact with Neo4j. I want to draw a relational graph but I can't figure out where the relationship data is in the transaction response, as the relationship arrays are all empty. The relationship data is clearly there somewhere, because the web interface is drawing a relationship graph from this data.

For example, when I run the query match (n) return (n), the web interface gives the following response data (this is from sample movie set provided with 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
}

I can't see the relationship data anywhere in here, and all relationship arrays are empty? Yet somehow, the web interface manages to draw this graph from this data: enter image description here

I'm clearly missing something critical about how to extract relational data from neo4j responses.

Upvotes: 1

Views: 46

Answers (1)

Tore Eschliman
Tore Eschliman

Reputation: 2507

Your query doesn't alias or return any relationships. The front end displays them because it displays any relationships that exist between the nodes it shows. Make your query something like MATCH () - [r] - () RETURN r and you'll see some relationship data show up.

EDIT: Your RETURN statement determines what data comes back from the API. If you don't ask it to return any relationships, the HTTP response won't contain them, but the browser view will intelligently display the relationships anyway. You can return a relationship, though, the same way you return a node: assign it an alias using a pattern, then return the alias.

Upvotes: 3

Related Questions