Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-10-2020 08:20 AM
Hi , thanks in advance.
I would like to set a relationship between 2 nodes with a property value instead of a conventional HAS_A , IS_A thingy. For example Patient has a Diagnosis for example Diabetes.
i want to say PATIENT-[:Diabetes]->Diagnosis{type:Diabetes}
PATIENT-[:Cancer]->Diagnosis{type:Cancer}
PATIENT-[:Thyroid]->Diagnosis{type:Thyroid}
Here instead of a Has a relation if i can keep the property values, i could easily count how many patients have Diabetes and Cancer etc., And more could be done easily as the data volume is huge.
Please let me know how.
Please keep the following things in mind:
Please format code + Cypher statements with the code </>
icon, it's much easier to read.
Please provide the following information if you ran into a more serious issue:
PROFILE
or EXPLAIN
with boxes expanded (lower right corner)Solved! Go to Solution.
07-11-2020 01:26 AM
Please check this link for Naming rules and recommendations:
https://neo4j.com/docs/cypher-manual/4.1/syntax/naming/
Non-alphabetic characters, including numbers, symbols and whitespace characters, can be used in names, but must be escaped using backticks
Here is how you can implement this in
CALL apoc.create.relationship(f, `p.DX_DOT`,{}, s) .
This will create the relationship as shown and you can run MATCH statement.
Here is sample code to illustrate this
match (a:Cat {name:'dadu'})
with a
merge (b:Chicken {name: 'chick'})
with a, b, 'HAS3.2' as r1
CALL apoc.create.relationship(a, `r1`,{}, b) YIELD rel
REMOVE rel.noOp
Result:
Added 1 label, created 1 node, set 1 property, completed after 31 ms.
match (a:Cat)-[:`HAS3.2`]->(b)
return a, b
Return the above graph.
07-10-2020 09:06 AM
For nodes and relationships labels one can have any name that makes sense to one's application.
07-10-2020 09:20 AM
Thanks. When i try to do this via CYPHER i am seeing syntax errors.
For example
MERGE (p:DX {PATIENTID:row.PATIENTID, DX_DOT:row.DX_DOT,SVCDATE:row.SVCDATE})
SET p.PRACTITIONER_ID = row.PRACTITIONER_ID,
p.YEARMONTH = row.YEARMONTH,
p.CLAIMID = row.CLAIMID
MATCH (pa:PTS {PATIENTID:row.PATIENTID})
MERGE (pa)-[:'HAS_DX'+p.DX_DOT]->(p)
This doesnt work for me.
But i tried to do apoc relationship and was able to establish the relationship type like below
now i am finding it hard to retrieve this relationship node via Match.
07-11-2020 01:26 AM
Please check this link for Naming rules and recommendations:
https://neo4j.com/docs/cypher-manual/4.1/syntax/naming/
Non-alphabetic characters, including numbers, symbols and whitespace characters, can be used in names, but must be escaped using backticks
Here is how you can implement this in
CALL apoc.create.relationship(f, `p.DX_DOT`,{}, s) .
This will create the relationship as shown and you can run MATCH statement.
Here is sample code to illustrate this
match (a:Cat {name:'dadu'})
with a
merge (b:Chicken {name: 'chick'})
with a, b, 'HAS3.2' as r1
CALL apoc.create.relationship(a, `r1`,{}, b) YIELD rel
REMOVE rel.noOp
Result:
Added 1 label, created 1 node, set 1 property, completed after 31 ms.
match (a:Cat)-[:`HAS3.2`]->(b)
return a, b
Return the above graph.
All the sessions of the conference are now available online