cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Creating a Relationship between 2 nodes

Hi there everyone,

I'm new to Neo4j. I'm picking up the basics at the moment, and I have a question regarding creating a specific kind of relationship creation.

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?

1 ACCEPTED SOLUTION

Hi @scienceofdata2021

Yes! You can create the relationships.

I created the data

CREATE (:Text {id: 1, text: "Graphs are everywhere"}),
       (:Text {id: 2, text: "I love graph theory"});
CREATE (:Keyword {textid: 1, id: 1, keyword: "Graphs"}),
       (:Keyword {textid: 1, id: 2, keyword: "are"}),
       (:Keyword {textid: 1, id: 3, keyword: "everywhere"}),
       (:Keyword {textid: 2, id: 1, keyword: "I"}),
       (:Keyword {textid: 2, id: 2, keyword: "love"}),
       (:Keyword {textid: 2, id: 3, keyword: "graph"}),
       (:Keyword {textid: 2, id: 4, keyword: "theory"});

and relationships

MATCH (k:Keyword),(t:Text)
  WHERE k.textid = t.id
CREATE (k)-[:IS_IN]->(t);

View solution in original post

2 REPLIES 2

Hi @scienceofdata2021

Yes! You can create the relationships.

I created the data

CREATE (:Text {id: 1, text: "Graphs are everywhere"}),
       (:Text {id: 2, text: "I love graph theory"});
CREATE (:Keyword {textid: 1, id: 1, keyword: "Graphs"}),
       (:Keyword {textid: 1, id: 2, keyword: "are"}),
       (:Keyword {textid: 1, id: 3, keyword: "everywhere"}),
       (:Keyword {textid: 2, id: 1, keyword: "I"}),
       (:Keyword {textid: 2, id: 2, keyword: "love"}),
       (:Keyword {textid: 2, id: 3, keyword: "graph"}),
       (:Keyword {textid: 2, id: 4, keyword: "theory"});

and relationships

MATCH (k:Keyword),(t:Text)
  WHERE k.textid = t.id
CREATE (k)-[:IS_IN]->(t);

Ahh i didn't think you can create a match that way, I'd assumed they would have to be matching values! Good to know going forward, and thank you so much for your swift and detailed response!