简体   繁体   中英

Creating a Relationship between 2 nodes

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)

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)

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