I am trying to populate the neo4j database from Kafka using a connector so the person node will constantly be created. I am trying to create a relationship between Person nodes if the timestamp is the same.
MERGE (n:Person{age: event.age, gender:event.gender, glasses:event.glasses })
ON CREATE SET n.id=event.id
WITH (n:Person) as n1, (n:Person) as n2 WHERE n1.event.time = n2.event.time AND n1<>n2
MERGE (n1)-[:was_at {timestamp: event.Time}] –(n2)
The timestamp sent over from my json file has the following format : 2020-10-08T10:29
The a variable - represents the person node found in the database
The b variable - represents another person node that has the same time property as the a variable found
However the above query doesn't work well after some time as the number of person nodes it is finding keeps increasing as you add more data. If the data your adding has the time property that keeps increasing then you can filter out the old person nodes. Query shown below:
MATCH (a:Person)
WHERE a.Time > 'some value'
MATCH (b:Person)
WHERE b.Time = a.Time AND NOT id(b) = id(a)
MERGE (a)-[:WAS_AT {timestamp: b.time}]->(b)
RETURN a, b
The Person node has age, gender, glasses, id properties as per your MERGE statement.
Under WHERE you are referring to n1.event.time . event.time is not a property of Person node. It's a value you are getting from Kafka. This should have raised an error by Neo4j. May be there is a typo!.