Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-09-2020 03:04 AM
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
Thanks for your help in advance!
10-11-2020 08:19 PM
Hi @james.irvin,
I am no expert but if this was my problem, I would split it into 2 queries.
To create the relationships I would use the query below
MATCH (a:Person)
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
Hope this helps you
10-13-2020 07:35 PM
Hi, thank you for the suggestion.
Can I know what does a and b represent because person nodes are constantly being inputed in.
10-13-2020 09:16 PM
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
10-12-2020 02:38 AM
...and remember to create constraint index 🙂
10-14-2020 08:42 PM
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!.
12-19-2020 01:46 PM
please check your event.time property for person node
All the sessions of the conference are now available online