Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-16-2021 11:25 AM
Hi,
I want to return virtual nodes and relationships by grouping on unique node properties. In our case this is to visualise/API data relating to single real-world entities: companies and people, using the company name and officer's data of birth to group by.
However, I can't bring through all the original node's properties in the final output?
I found this example which does pretty much want I need and have adjusted it to:
//Match officer surname, forename, dob
MATCH (c:Company)-[io:IS_OFFICER]->(o:Officer)
WHERE o.surname = "OATEN" AND o.forenames STARTS WITH "MICHAEL" AND o.partialdateofbirth IS NOT NULL
//Collect distinct company names and dob's
WITH collect(distinct c.name) as names, collect(distinct o.partialdateofbirth) as dobs
//Group by distinct company name and dob's
WITH [cname IN names | apoc.create.vNode(['Company'],{name:cname})] as nNodes,
[dobname IN dobs | apoc.create.vNode(['Officer'],{dob:dobname})] as dNodes
WITH apoc.map.groupBy(nNodes, 'name') AS nvs,
apoc.map.groupBy(dNodes, 'dob') AS dvs
//Repeat original query to make all properties available
MATCH (c:Company)-[io:IS_OFFICER]->(o:Officer)
WHERE o.surname = "OATEN" AND o.forenames STARTS WITH "MICHAEL" AND o.partialdateofbirth IS NOT NULL
WITH nvs, dvs, io, c, o
RETURN
nvs, dvs, apoc.create.vRelationship(nvs[c.name], 'IS_OFFICER', io{.*}, dvs[o.partialdateofbirth]) AS rel
LIMIT 100
The query is doing its main job of grouping by distinct company name and distinct date of birth and the virtual relationship is also correct; and has all the properties from the actual relationship.
But how do I add all the original Officer properties and Company properties to their virtual equivalents?
Thanks in advance for any help
All the sessions of the conference are now available online