How to create a tweet hierarchy tree structure in Neo4j?

200 Views Asked by At

1.I was trying to build the relationships between each tweet nodes. A tweet can have multiple reply tweets and retweet tweets. Assuming I have two nodes which name Tweet and Tweets respectively. If Tweet.id = Tweets.reply_toid the relationship can be (Tweets)-[:replyto]->[Tweet]. If Tweet.id = Tweets.retweet_id the relationship can be (Tweets)-[:retweet]->[Tweet]. How can I create a tree structure like the screenshot below? enter image description here

2 For example, A tweet ID is 123 , reply_to is 321, another tweet ID is 321 and the reply_to id is 456. Then the graph should be like 123-[reply]->321-[reply]->456. But for my result , I got separate reply_to results: 123-[reply]->321 321-[reply]->456. How can I create a hierarchy tree just like the screenshot photo?

CALL apoc.load.json("file:///tweets.json")
YIELD value
MERGE (t:Tweet {id: value.id})
WITH t, value
where exists(value.retweet_id) 
MERGE (c:Tweet {id: value.retweet_id})
MERGE (t)-[:retweet]->(c)
WITH t, value
where exists(value.replyto_id) 
MERGE (T:Tweet {id: value.replyto_id})
MERGE (t)-[:reply]->(T);
0

There are 0 best solutions below