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.

How to merge MERGE AND MATCH with CSV import

sample CSV lines are as follows

created_at,tweet_id,retweeted_user_screenName,retweeted_user_id,tweet_text,screen_name,source,hashtags,user_mentions,in_reply_to_status_id,in_reply_to_user_id,is_quote_status,retweet_count,favorite_count,favorited,retweeted,userid,name,location,protected,followers_cnt,friends_cnt,listed_cnt,favourites_count,statuses_count,verified,contributors_enabled,lang,user_creation_dt_at,max_id,since_id,query,next_results,result_type,user_description
3/23/2019 8:42,1.11E+18,NOBODY,0, Tributes to Shaheed Bhagat Singh Shivaram #Rajguru and #Sukhdev Thapar who were hanged by Britishers this day in 1931. Salute to the Bravest Sons Of India who lived for the country and died for the country. #MartyrsDay #BhagatSingh #ShaheedDiwas #ShaheedBhagatSingh https://t.co/fwj2uGDQaE, Being_Savvy, TwitterforAndroid, ['Rajguru'; 'Sukhdev'; 'MartyrsDay'; 'BhagatSingh'; 'ShaheedDiwas'; 'ShaheedBhagatSingh'], , , , False,0,0, False, False,2876088965, Savvy Tarafdar, Kolkata India, False,914,96,7,3876,3212, False, False, en, 2014-11-14 06:34:18,1.11E+18,0, %23Sukhdev, ?max_id=1109374390137815041&q=%23Sukhdev&count=100&include_entities=1&result_type=recent, recent, Musician | YouTuber Entertainer | Photographer | Story Teller | Artist ? TikTok / Snapchat : @ savvytarafdar ? Contact : thesavvy99@gmail.com ??
3/23/2019 8:42,1.11E+18, BJP4Maharashtra,532895350, RT @BJP4Maharashtra: तरुणांच्या मनावर आजही अधिराज्य गाजवणारे शहीद-ए-आज़म भगतसिंग सुखदेव आणि राजगुरू यांचा आज बलिदान दिवस. त्यांच्या स्मृ…, archanamuth1, TwitterWebClient, , ['BJP4Maharashtra'], , , False,23,0, False, False,1.09E+18, archanamuth, , False,33,38,0,62,1488, False, False, en, 2019-02-06 06:24:03,1.11E+18,0, %23Sukhdev, ?max_id=1109374390137815041&q=%23Sukhdev&count=100&include_entities=1&result_type=recent, recent,

CSV header is like bellow :
created_at,tweet_id,retweeted_user_screenName,retweeted_user_id,tweet_text,screen_name,source,hashtags,user_mentions,in_reply_to_status_id,in_reply_to_user_id,is_quote_status,retweet_count,favorite_count,favorited,retweeted,userid,name,location,protected,followers_cnt,friends_cnt,listed_cnt,favourites_count,statuses_count,verified,contributors_enabled,lang,user_creation_dt_at,max_id,since_id,query,next_results,result_type,user_description

I am running following 2 queries

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///D:/Tools/ori_twecoll/twecoll-master/Sukhdev.csv" As row
MERGE (user:User{screen_name:trim(row.retweeted_user_screenName),userid:row.retweeted_user_id})
RETURN user.screen_name

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///D:/Tools/ori_twecoll/twecoll-master/Sukhdev.csv" As row
MATCH (user:User{screen_name:row.trim(retweeted_user_screenName),userid:row.retweeted_user_id})
MATCH (userInSys:User{screen_name:row.screen_name})
CREATE UNIQUE (user)-[:RETWEETED_BY]->(userInSys)
RETURN user.screen_name,userInSys.screen_name

I want to combine them into one query. Can anyone help?

2 REPLIES 2

ameyasoft
Graph Maven

Try this :
MERGE (user:User{screen_name:trim(row.retweeted_user_screenName),userid:row.retweeted_user_id})
MERGE (userInSys:User{screen_name:row.screen_name})
MERGE (user)-[:RETWEETED_BY]->(userInSys)

Only merge on one unique property, i.e. the user id OR the screen-name!

Otherwise you will get duplicates. B/c merging on both will match against both keys at the same time.