如何结合与CSV导入相关的密码查询?

时间:2019-03-23 15:18:28

标签: neo4j cypher

示例CSV行如下:

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. :pray::muscle::india: #MartyrsDay #BhagatSingh #ShaheedDiwas #ShaheedBhagatSingh httpt.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 : thesavvy99gmail.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,

我正在跟踪以下2个查询

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

我想将它们组合成一个查询。

1 个答案:

答案 0 :(得分:0)

您可以使用 MERGE 创建用户(如果不存在),然后使用以下查询创建所需的关系。

请考虑使用 MERGE ,而不是已弃用的 CREATE UNIQUE

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

建议:

  • 不要在单个查询中合并多个MERGE,请考虑多个 查询,并在以后的查询中使用MATCH。
  • 不要在数据加载查询本身中返回结果,请考虑 另一个查询。
  • 在节点的键上创建索引