I had created two group of nodes in graph using the following cypher query
pharma group
CREATE ( p1:pharma { name: " Magnesium ", id: " 12 " } )
CREATE ( p2:pharma { name: " Hyoscine Butylbromide ", id: " 22 " } )
CREATE ( p3:pharma { name: " Propantheline Bromide ", id: " 23 ", } );
ind group
CREATE ( i1:ind { id: '1', name: 'Dyspepsia', pdfk: '12'})
CREATE ( i2:ind { id: '5', name: 'Symptomic relief of intestinal disorder', pdfk: '22'})
CREATE ( i3:ind { id: '6', name: 'Symptomic relief of disorder', pdfk: '22'})
CREATE ( i4:ind { id: '7', name: 'Bowel colic', review: 'False', pdfk: '23'});
its just like relational database tabels, Now I want to define relation ship between these two group of nodes..
relationship like = node in pharma with id 12 has a relationship name HAS_IND with node in ind with id 1 ?
somewhere like this
MATCH (a:pharma),(b:ind)
WHERE a.id = '12' AND b.id = '1'
CREATE (a)-[:has_ind]->(b);
I tried these too
MATCH (a:pharmaDrug),(b:indication)
WHERE a.name = 'Magnesium Carbonate' AND b.name = 'Dyspepsia'
CREATE (a)-[:has_indication]->(b);
but both are giving Returned 0 rows in 530 ms in the console ?
Please help me to find the correct cypher query for this purpose. Thanks in advance.
========================================================================
My changes are as follows
CREATE ( p1:pharma { name: "Magnesium", id: 12 } )
CREATE ( p2:pharma { name: "Hyoscine Butylbromide", id: 22 } )
CREATE ( p3:pharma { name: "Propantheline Bromide", id: 23 } );
CREATE ( i1:ind { id: 1, name: 'Dyspepsia', pdfk: '12'})
CREATE ( i2:ind { id: 5, name: 'Symptomic relief of intestinal disorder', pdfk: '22'})
CREATE ( i3:ind { id: 6, name: 'Symptomic relief of disorder', pdfk: '22'})
CREATE ( i4:ind { id: 7, name: 'Bowel colic', review: 'False', pdfk: '23'});
this create nodes under two labels
MATCH (a:pharma),(b:ind)
WHERE a.id = ' 12 ' AND b.id = ' 1 '
CREATE (a)-[:has_indication]->(b);
this give zero rows affected with no output ?
It's because of the way you've created your items, if you look at your 'pharma' code you have:
To match against this you need to do:
I've added extra spaces around the '12' to get it to match. So you're query would read as:
Now, that'll get it to work - but it might be worth changing your model a bit, if the
idis always an integer, I would change your creates to being:and be SUPER careful with your use of the
"(or') character, in your original creates you are adding extra spaces for the names as well (which is why your second query didn't work)EDIT
OK, this is a fully working set of data, I've edited both of your create statements to get this:
Basically I've removed the
'characters and used integers for id (and pdfk). TheMATCHfor this is:And to check it works (aside from the message you get back):
You'll see one is linked to another.