Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-07-2019 09:03 AM
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)
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
Solved! Go to Solution.
05-25-2021 09:04 AM
Thanks for sharing the file. Column header, 'id' is missing in Column A. Add 'id' in the row 1 and column 1 and try.
11-07-2019 09:38 AM
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{ ... .....
05-25-2021 06:00 AM
how did it work? facing the same problem
05-25-2021 06:51 AM
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)
05-25-2021 06:55 AM
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
05-25-2021 07:30 AM
05-25-2021 08:34 AM
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.
05-25-2021 09:00 AM
05-25-2021 09:04 AM
Thanks for sharing the file. Column header, 'id' is missing in Column A. Add 'id' in the row 1 and column 1 and try.
05-25-2021 09:12 AM
thank you !!! it worked
All the sessions of the conference are now available online