Good day all,
Being new to graph and neo4j I am having a bit of trouble in my execution.
Setup: I have a data model of (:Client)-[:HAS_A_CHARACTERISTIC]->(:Characteristic). There are many characteristics (~230) and I am using these characteristics to create a direct relation between clients (i.e. (:Client)-[:MUTUAL]-(:Client)). The [:MUTUAL] relation will have a strength of [common_characteristics / max(client1_chars,client2_chars)].
I am able to calculate these values and even create these relationships, however it goes without saying that these are actually bi-directional relations, and therefore two relationships are being created. This is not a problem with a very small subset, however I have ~2.2mil client nodes.
How do I create a single relationship?
Below is the query that I have used:
match (i:`Cape Town`)-[]->(b)<-[]-(j:`Cape Town`)
with i, j, count(b) as comm_bh
unwind [i.bh_degree,j.bh_degree] as bh_degs
with i,j,comm_bh,max(bh_degs) as deg_denom
with i,j,comm_bh,deg_denom, case when exists((j)--(i)) then true else false end as created_ind
foreach (n in case when created_ind then [] else [1] end |
create (i)-[m:MUTUAL]->(j) // merge also creates duplicates...
set m.strength=(comm_bh*1.0/deg_denom))
return i as start_node, comm_bh, deg_denom,created_ind, j as end_node