I'm trying to use existing data to create a new relationship type. I'm trying the strategy in this question but I'm not getting the expected results.
This:
MATCH (user)-[r:POSTS_TO]->(thread)<-[s:POSTS_TO]-(other)
MERGE (user)-[act:TALKS_TO]->(other)
works, creating unique relationships between users who have posted in the same forum threads, but there are no relationship properties set for TALKS_TO
. I'd like to add the number of threads each user share to the relationship, with the aim to delete the underlying POSTS_TO
relationships.
When I try this:
MATCH (user:User)-[r:POSTS_TO]->(thread:Thread)<-[s:POSTS_TO]-(other:User)
WITH thread, count(r.thread_id) as total_threads
MERGE (user)-[act:TALKS_TO]->(other)
ON CREATE SET act.total_threads = thread.total_threads
only two nodes (neither of which are user nodes) and one relationship are set, and no properties.
I have also tried
MATCH (user:User)-[r:POSTS_TO]->(thread:Thread)<-[s:POSTS_TO]-(other:User)
WITH thread, count(thread) as total_threads
MERGE (user)-[act:TALKS_TO]->(other)
ON CREATE SET act.total_threads = thread.total_threads
with the same results.
I can't see where I am going wrong in comparison with this question. Critiques & corrections please?
This is the full set of data that I'd like to set as a property for each TALKS_T0
relationship:
MATCH (user)-[r:POSTS_TO]->(thread)<-[s:POSTS_TO]-(other)
WITH r,
min(r.event_time) as first_post,
max(r.event_time) as last_post,
count(distinct r.post_id) as total_posts,
count(distinct r.thread_id) as total_threads,
count(distinct r.forum_id) as total_forums
MERGE (user)-[act:TALKS_TO]->(other)
ON CREATE SET act.first_post = first_post,
act.last_post = last_post,
act.total_posts = total_posts,
act.total_threads = total_threads,
act.total_forums = total_forums