aliteralmind
aliteralmind

Reputation: 20163

Cypher relationships disconnected from nodes (pointing to nothing). Variable names wrong?

I'm expecting this script

// $ cd ~/Documents/neo4j-community-2.2.5/bin
// $ ./neo4j-shell -file ~/Documents/neo4j_input/neo4j_queries.txt    

//Purge
MATCH ()-[r]-() DELETE r;
MATCH (n) DELETE n;    

CREATE (p1:Person { first_name: "Apple", age: 9 });
CREATE (p2:Person { first_name: "Bear", age: 44 });    

CREATE (p2)-[x:ISPARENTOF]->(p1);
CREATE (p1)-[x2:ISCHILDOF]->(p2);

to look like this, with the relationships pointing from each person to the other:

     -ISCHILDOF->
(p1)             (p2)
    <-ISPARENTOF-

But instead the relationships are pointing to thin air. What am I missing?

enter image description here

Upvotes: 0

Views: 48

Answers (1)

Nicole White
Nicole White

Reputation: 7790

Identifiers are only relevant within the scope of the query. You're executing separate queries.

CREATE (p1:Person { first_name: "Apple", age: 9 });
CREATE (p2:Person { first_name: "Bear", age: 44 });    

CREATE (p2)-[x:ISPARENTOF]->(p1);
CREATE (p1)-[x2:ISCHILDOF]->(p2);

In the 3rd and 4th queries, p1 and p2 are not bound to anything. You're creating nodes with no labels and no properties. You just need to remove the semicolons so that it's one query.

CREATE (p1:Person { first_name: "Apple", age: 9 })
CREATE (p2:Person { first_name: "Bear", age: 44 })

CREATE (p2)-[x:ISPARENTOF]->(p1)
CREATE (p1)-[x2:ISCHILDOF]->(p2);

In this query, p1 and p2 are bound when they're created at lines 1 and 2 respectively and used again at lines 4 and 5.

Upvotes: 1

Related Questions