I would like to have some guidance on creating a relationship between two existing nodes without introducing new nodes. The canonical way of doing this should be something like:
MATCH (entity: Entity{ collection_id: 10 })
MATCH (rule: Rule{ collection_id: 10, id: "strength_greater_than_0", column: "strength", operation: "greater_than", value: "0" })
WHERE entity.strength > 0
MERGE (rule)-[r:APPLIES_TO]->(entity);
However, despite the indexes on entity.strength and rule.id as well as rule.column , rule.operation and rule.value this request does not complete.
- When I do a count instead, it returns immediately
- When I do a
createinstead of amergeit will finish in 6 seconds, but then I believe it creates new entities as well in the process
When I say I believe then I am simply stating that I am confused by the message the browser gives me when employing the create variant:
MATCH (entity: Entity{ collection_id: 10 })
MATCH (rule: Rule{ collection_id: 10, id: "strength_greater_than_0", column: "strength", operation: "greater_than", value: "0" })
WHERE entity.strength > 0
CREATE (rule)-[r:APPLIES_TO]->(entity);
which states:
Created 586131 nodes, set 1172262 properties, created 586131 relationships, completed after 5834 ms
When I count the entity nodes or the Rule nodes, then no new nodes are introduced, but then in that case, why is it stating: Created 586131 nodes if it only introduced relationships?
I also tried the following:
MATCH (entity: Entity{ collection_id: 10 })
WHERE entity.strength > 0
MERGE (Rule{ collection_id: 10, id: "strength_greater_than_0", column: "strength", operation: "greater_than", value: "0" })-[r:APPLIES_TO]->(entity);
as such a Rule is unique anyways to no avail. It runs forever.
I also tried something like:
MATCH (entity: Entity{ collection_id: 10 })
MATCH (rule: Rule{ collection_id: 10, id: "strength_greater_than_0", column: "strength", operation: "greater_than", value: "0" })
WHERE entity.strength > 0 AND NOT (rule)-[:APPLIES_TO]->(entity)
CREATE (rule)-[r:APPLIES_TO]->(entity);
this also keeps running forever.