Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-26-2021 10:03 AM
I need to create company and parent company relations from a json file, however some companies do not have parent companies, like this example
{ "company_id" : 2032,
"parent_company_id" : 343
}
{ "company_id" : 2332,
"parent_company_id" :
}
It is possible to create company-paranet company relation when a company has parent company, skip the company if it does not have parent company or substitute null with some characters?
Thanks.
02-26-2021 11:48 AM
Hi @jzhou002 ,
Welcome to the Graph Community.
I tried this with the below sample data and query :
{
"company_id" : 2032,
"parent_company_id" : 343
}
{
"company_id" : 2332,
"parent_company_id" :0
}
QUERY :
call apoc.load.json("file:///testjson.json")
yield value AS row
WITH row where row.parent_company_id<>0
MERGE(c:Company{companyId:row.company_id})-[:HAS_PARENT]->(pc:Company{companyId:row.parent_company_id})
RETURN c,pc
Below is the output :
Please let me know if this is what you need or did I miss anything.
02-27-2021 03:43 PM
Oh cool. Thank you very much. I am new to cypher, a lot to learn.
All the sessions of the conference are now available online