Reputation: 563
I have a neo4j database up and running. I also have a process that runs every 5 minutes and what it does is to create nodes of type "Point".
"Point" has the following properties:
pointId, cameraId, classId, groupId, datetime
Nodes of type "Point" relate to themself if: pointId & cameraId & classId & groupId are the same.
Is it possible to somehow get all the nodes "Point" that relate themself and based on that group of nodes create a new node "Line" where "Line"-[:CONTAINS]->"Point"?
UPDATE: Following image shows what I have and what I need. For simplicity, I've just defined the property "camera", if a node Point shares the camera then it needs to be grouped.
Upvotes: 1
Views: 296
Reputation: 4052
Yes, it's possible.
You need to collect all the points for each pair of these properties. Then create the Line
node and then create a relationship between the created line and all the grouped points.
Add the required properties to the line node in the following query.
MATCH (p:Point)
WITH p.pointId as pointId, p.cameraId as cameraId, p.classId as classId, p.groupId as groupId, collect(p) as related_points
CREATE (line:Line)
WITH line, related_points
UNWIND related_points as point
CREATE (line)-[:CONTAINS]->(point)
Upvotes: 1