cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Why there is no link between root node and child node?

CREATE (n:Tweet {id:'123', title:'A'})
CREATE (cl1:TweetLeaf {id:'234', title:'IT Team', reply_to:'123'})
CREATE (cl2:TweetLeaf {id:'testingTeam', title:'TESTING Team', reply_to:'234'})
CREATE (cl3:TweetLeaf {id:'588', title:'TESTING Team', reply_to:'testingTeam'})
CREATE (cl4:TweetLeaf {id:'kk', title:'TESTING Team', retweet_to:'588'})
CREATE (cl5:TweetLeaf {id:'119', title:'TESTING Team', retweet_to:'kk'})

CREATE (n:Tweet:Node {id:'588', title:'B'})

MATCH (c: TweetLeaf)
WHERE NOT (c)-[:reply_to]->() or not (c)-[:retweet_to]->()

MATCH (parent:Tweet {id:c.reply_to})
WITH parent, c
MERGE (c)-[:reply_to]->(parent)

MATCH (c: TweetLeaf)
WHERE NOT (c)-[:reply_to]->() or not (c)-[:retweet_to]->()

MATCH (retweet:Tweet {id:c.retweet_to})
WITH c, retweet
MERGE (c)-[:retweet_to]->(retweet)`Preformatted text`

The output should like the screenshot below:

However, my output just like this(AB should link to A but there is no relationship between node AB and node A):

3 REPLIES 3

@ChengLiangcl, Try these

MATCH (c: TweetLeaf)
WHERE NOT (c)-[:reply_to]->() or not (c)-[:retweet_to]->()
MATCH (parent:TweetLeaf {id:c.reply_to})
WITH parent, c
MERGE (c)-[:reply_to]->(parent);

MATCH (c: TweetLeaf)
WHERE NOT (c)-[:reply_to]->() or not (c)-[:retweet_to]->()
MATCH (retweet:TweetLeaf {id:c.retweet_to})
WITH c, retweet
MERGE (c)-[:retweet_to]->(retweet);

it does not work at all

The Cypher you provided does not match results in your graph data. There is no :TweetLeaf node with title:'AB' in the cypher you provided.

More importantly, note the labels you're using when you match on the parent. Your Cypher is looking for :Tweet nodes, but there are only two :Tweet nodes in the Cypher you provided (for 'A' and for 'B'). Consider if :TweetLeaf nodes should also have the :Tweet label, then they would be matched to when finding the parent.