简体   繁体   中英

Importing a CSV file to neo4j with a column that has csv values

I have a CSV file that contains a userid, an email, names and finally a contacted field.

The contacted field shows other users that the user has contacted, but in the case of multiple users it contains a list where each user that has been contacted is seperated by a ','.

For instance, I have the entry:
1,noaddress@fake.com,fakename,"4,5,6,7"
which means user with userid 1 contacted users with id 4, 5, 6 and 7.

How can I import this to neo4j while creating a 'contacted' relationship between 1 and 4,5,6,7?

I have very little experience with neo4j and cypher, and have thus been struggling with this quite a bit and am not finding the documentation particularly helpful.

Any help is appreciated.

You'll want to use split() on the field, using ',' as the delimiter, to get a list of elements. Then you can either UNWIND or use FOREACH to process the elements of the list, probably to MATCH on nodes with the given id.

Keep in mind that all fields are treated as strings, so you will have to use toInteger() to cast the values if you want to treat them as numerics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM