-
Creating Nodes and Relationships with Ownership Percentages in Neo4j
-
I have written query sets up a graph in Neo4j where each node represents either an individual or an entity. The relationships between the nodes indicate ownership with specified percentages. This structure models an organizational hierarchy, capturing both the parent-child relationships and the ownership stakes between them.
Now I wanted to fetch data from the graph.
Example:
I have some senerio like this
// Create nodes
CREATE (a:Entity {id: 4, parentId: "", name: "A", ownership: "50%", email: "a@example.com", phone: "1234567890", individualOrEntity: "Entity"})
CREATE (b:Individual {id: 88, parentId: "4", name: "B", ownership: "20%", email: "b@example.com", phone: "2345678901", individualOrEntity: "Individual"})
CREATE (c:Individual {id: 77, parentId: "88", name: "C", ownership: "15%", email: "c@example.com", phone: "3456789012", individualOrEntity: "Individual"})
CREATE (d:Entity {id: 55, parentId: "4", name: "D", ownership: "15%", email: "d@example.com", phone: "4567890123", individualOrEntity: "Entity"})
// Create relationships with ownership percentages
CREATE (a)-[:PARENT_OF {ownership: "20%"}]->(b)
CREATE (b)-[:PARENT_OF {ownership: "15%"}]->(c)
CREATE (a)-[:PARENT_OF {ownership: "15%"}]->(d)
when we create the node and if we have id of any node "A" then it should return all the node which is related to it.
This is my graph look like
The query which i am using :;
MATCH p=(root {id: '7f633886-7194-4676-a154-77c6751eb6bb'})-[:OWNS*]-(child) RETURN nodes(p) AS interconnectedNodes
- here P is the parent node and we have only id of this node I wanted to fetch all the property of each node the query which is written in the attached photo it's returning the node but there is lots of data which I dont want.
Solution which I want:
- when we pass the parent node Id then it should return all node which is connected to it directly or indirectly with label and property.
So can you please help me with the query which will return only the Node - label and it's property ?
please provide the solution in apoc or other solution as well