cancel
Showing results for 
Search instead for 
Did you mean: 

No changes, no records - associating two nodes

rebecca_carlisl
Node Link

Hi there,

I am trying to associate two nodes of the same kind/label. Companies are represented by nodes and the relationship is the association one company has to another i.e. Shareholder, Parent etc. I have simiplified my dataset down in order to get the correct cypher query before trying to create thousands of relationships.

I have successfully created two nodes through a csv load. 'CompanyABC' and 'CompanyXYZ' with their associated unique IDs. I also created an index on LegalEntityID.

The csv looks like the following;
LegalEntityID,LegalEntityName

225176,CompanyABC

12470,CompanyXYZ

(see below screenshot - there are no whitespaces at all)
2X_7_78c9b9875701d88842db371cec5ef41e23a48f88.jpeg

The cypher query I used to create the nodes is:

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS csvLine

CREATE (e:Entity {Id: toInteger(csvLine.LegalEntityID), LegalEntityName: csvLine.LegalEntityName})

I then tried to associate these two nodes using the below;

Match (a:LegalEntityID),(b:LegalEntityID) where a.LegalEntityID = '225176' and b.LegalEntityID = '12470' create (b)-[r:HAS_ASSOCIATION]->(a)

I received the response: (no changes, no records)

I then tried the below;

MATCH (a:LegalEntityID{LegalEntityID:toInteger(225176)}),(b:LegalEntityID{LegalEntityID:toInteger(12470)})

CREATE (b)-[r:hasAssociation]->(a)

RETURN b,r,a

and I still got the response (no changes, no records) - see below screenshot

Please could you let me know where I am going wrong – I have tried everything!

Thanks and regards
Rebecca

1 ACCEPTED SOLUTION

Thanks for sharing the file. Column header, 'id' is missing in Column A. Add 'id' in the row 1 and column 1 and try.

View solution in original post

9 REPLIES 9

dana_canzano
Neo4j
Neo4j

Your LOAD CSV statement is creating nodes with a label named 'Entity`. For example your CREATE statement is

CREATE (e:Entity {Id: toInteger(csvLine.LegalEntityID), LegalEntityName: csvLine.LegalEntityName})

as such your MATCH statements should be on the Entity label and not the LegalEntity. So

MATCH (a:LegalEntityID{.... .....

should be replaced as

MATCH (a:Entity{ ... .....

how did it work? facing the same problem


MATCH (a:LegalEntityID{LegalEntityID:toInteger(225176)}),(b:LegalEntityID{LegalEntityID:toInteger(12470)})

CREATE (b)-[r:hasAssociation]->(a)
[/quote]

Per the screenshot, original author created node, 'Entity' with properties 'id' and 'LegalEntityName'. The correct Cypher to create the relationship is:

MATCH (a:Entity {id:toInteger(225176)})
MATCH (b:Entity {id:toInteger(12470)})
MERGE (b)-[r:hasAssociation]->(a)

LOAD CSV WITH HEADERS FROM 'file:///final.csv' AS row

WITH row WHERE row.id IS NOT NULL

MERGE(d:Disease{name:row.disease})

CREATE(d2:Drug{name:row.drug})

CREATE(d)-[:TAKEN_FOR]->(d2)

CREATE(d2)<-[:LINKED_TO]-(d)

what should i change here

Check your final.csv file to see if 'id' column exists and has values and not nulls. Post a line from your .csv file with headers for testing.

3X_0_1_01f11316cdcdd89c25c9eacdd4b2a31d04e9dfdf.png

Thanks for sharing the file. Column header, 'id' is missing in Column A. Add 'id' in the row 1 and column 1 and try.

thank you !!! it worked