Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-10-2021 04:08 AM
Hi everyone, I am trying to import some data into neo4j from a CSV file and I am struggling to figure out exactly how to get the result I want.
The first column is the id of the recipe, second column is the name, third is the list of ingredients, forth column contains the amount of each ingredient, and the final column contains the unit that is meant to go with that amount. Using this data, I am attempting to create a graph database with the following structure:
I know how to unwind the ingredient list to create multiple ingredient nodes and create the appropriate relationships between the recipes and the ingredients, but I am stumped when it comes to adding the appropriate "amount" and "units" values to the relationships as attributes. I am using the APOC extension to load the csv.
Any help would be very much appreciated. Apologies if something similar has been brought up before, but I have genuinely been unable to find any post online discussing a similar issue.
01-10-2021 10:35 AM
Hi, Welcome to the neo4j community
I think that you could do the CSV with row individually or you could try the following:
with recipe, ingredientlist, amountlist
MERGE (rec:Recipe{name:recipe})
WITH collect(ingredientlist) AS ingredientcollect,
WITH collect(amountlist) AS amountcollect, range(0,size(ingredientcollect)-1,1) AS coll_size
WHERE size(ingredientcollect) = size(amountcollect)
UNWIND coll_size AS idx
MERGE (ing:Ingredient{name:ingredientcollect[idx]})
MERGE (rec) - [:CONTAINS_INGREDIENT{amount:amountcollect[idx]}] -> (ing)
Thanks
01-20-2021 09:05 PM
Thank you for the reply! How could I go about doing the CSV with row individually?
All the sessions of the conference are now available online