Reputation: 129
I'm trying to ingest data from Kafka to Neo4j via the neo4j-stream
plugin.
Currently we are experimenting with the CUD
strategy.
I wonder how we should deal with interconnected data.
Let's assume we stream 100 persons from Kafka to Neo4j.
When person(id:1)
has a relationship is_friends_with
with person(id:50)
we can not create this relationship until the node for person(id:50)
is created.
However, we have no control about the order of how the events are coming from Kafka.
So when the person data arrives, we would create the following CUD data:
person(id:1)
is_friends_with(person1, person50)
.person(id:50)
Unsurprisingly, when we ingest the events in this order the relationship is missing.
How can we deal with this?
Upvotes: 0
Views: 140
Reputation: 5385
I think this is a typical case to use MERGE.
Every time you have a relationship (which has start and end nodes) you do
MERGE (n:Person {id:foo})
MERGE (m:Person {id:bar})
MERGE (n)-[:is_friends_with]-(m)
The merge for the relationship does NOT have a direction, in order to avoid bi-directional patterns in case n and m arrive in different order.
Upvotes: 2