Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-21-2019 06:19 AM
I have build a toy database , with Stock and Industry.
Basically I have 25 Industry and about 8000 Stock. I want to create a link from the stock to industry.
I have a stock.csv with
stock_id, setupDate, name ....
and a stock_industry.csv with
stock_id, name, c_name
Then I first create nodes with Stock by the following:
USING PERIODIC COMMIT 300
LOAD CSV WITH HEADERS FROM "file:///stock.csv" AS stock_industry
MERGE (s:Stock { stock_id:stock_industry.stock_id ... })
RETURN count(s)
I then create the the industry nodes with only the industry name.
Then I want to create a "is_industry_of" relationship between the industry nodes and stock nodes:
LOAD CSV WITH HEADERS FROM "file:///stock_industry.csv" AS stock_industry
MATCH (s:Stock),(i:Industry)
WHERE s.stock_code=stock_industry.code AND i.industry=stock_industry.c_name
CREATE (s)-[r:is_industry_of]->(i)
RETURN count(s)
Then I got 0 results.
I searched the Internet, everyone has the third csv file as the relationship between "stock_code, industry_name".
However, I have a csv with the "stock_code, stock_name, industry_name".
Should I just use this csv and avoid using the relation-database-like one?
Solved! Go to Solution.
12-21-2019 06:22 AM
You've just got this piece the wrong way around. Rather than doing this:
You should do this:
LOAD CSV WITH HEADERS FROM "file:///stock_industry.csv" AS stock_industry
MATCH (s:Stock { id: stock_industry.id })
MERGE (i:Industry { name: stock_industry.name, c_name: stock_industry.c_name })
MERGE (s)-[:is_industry_of]->(i)
RETURN count(i);
12-21-2019 06:22 AM
You've just got this piece the wrong way around. Rather than doing this:
You should do this:
LOAD CSV WITH HEADERS FROM "file:///stock_industry.csv" AS stock_industry
MATCH (s:Stock { id: stock_industry.id })
MERGE (i:Industry { name: stock_industry.name, c_name: stock_industry.c_name })
MERGE (s)-[:is_industry_of]->(i)
RETURN count(i);
12-21-2019 07:20 AM
Thanks! Problem perfectly solved!
All the sessions of the conference are now available online