cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to use Node properties to set Relationship values instead of a constant HAS_A , IS_A thingy?

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:

  1. did you search for what you want to ask before posting?
  2. please use tags for additional info
  3. use a self-descriptive title

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:

  • neo4j version, desktop version, browser version
  • what kind of API / driver do you use
  • screenshot of PROFILE or EXPLAIN with boxes expanded (lower right corner)
  • a sample of the data you want to import
  • which plugins / extensions / procedures do you use
  • neo4j.log and debug.log
1 ACCEPTED SOLUTION

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.

2X_b_b6640daddc02d0be163b49a14ed5dabff1451699.png

match (a:Cat)-[:`HAS3.2`]->(b)
return a, b

Return the above graph.

View solution in original post

4 REPLIES 4

ameyasoft
Graph Maven

For nodes and relationships labels one can have any name that makes sense to one's application.

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
2X_7_7d28487b1c163787481e52d92a00fc5ac52f8c08.png

now i am finding it hard to retrieve this relationship node via Match.

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.

2X_b_b6640daddc02d0be163b49a14ed5dabff1451699.png

match (a:Cat)-[:`HAS3.2`]->(b)
return a, b

Return the above graph.

Yup. I got to it finally. Thank you so much @ameyasoft. This was helpful.