Reputation: 1
I'm new to Neo4j, and still getting my feet wet. I have a question regarding creating a specific kind of relationship.
I have 2 files:
File 1 has text data, and an ID field. File 2 has 3 fields - one keyword field, which is a text/keyword extracted from the text data from the previous file, a ID called text ID which refers to and is the same as the text ID from the previous file, and an ID for the keyword itself.
I have 2 nodes created, the Text node which has the properties Text ID and text, and a Keyword node, which just has the property "keyword". Is there anyway for me to create a relationship between these 2 nodes, where I would base of the text ID's in both files, and create a relationship which is k.keyword - [:IS_IN] - t.text?
This is what I tried to run so far, but I'm not sure what to do further:
LOAD CSV WITH HEADERS FROM "file:///text.csv" AS row1
LOAD CSV WITH HEADERS FROM "file:///keyword.csv" AS row2
MATCH(t:Text {text_id:row1.text_id}), (k:Keyword {keyword:row2.Keyword})
//The part which I don't know what to do
MERGE (k)-[:IS_IN]->(t)
Upvotes: 0
Views: 51
Reputation: 19373
Load each csv separately.
The first run creates the text nodes. Example:
LOAD CSV WITH HEADERS FROM "file:///text.csv" AS row1
MERGE (t:Text {text_id:row1.text_id})
SET t.text=row1.text
The second run creates the keyword, looks up the text node by id and creates the relationship. Example:
LOAD CSV WITH HEADERS FROM "file:///keyword.csv" AS row
MERGE (k:Keyword {keyword:row.Keyword})
WITH row,k
MATCH (t:Text {text_id:row.text_id}),
MERGE (k)-[:IS_IN]->(t)
Upvotes: 1