1

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 ?

Gopipuli
  • 393
  • 1
  • 12
  • 37

1 Answers1

4

It's because of the way you've created your items, if you look at your 'pharma' code you have:

CREATE ( p1:pharma { name: " Magnesium ", id: " 12 " } )

To match against this you need to do:

MATCH (a:pharma) 
WHERE a.id = ' 12 '
RETURN a

I've added extra spaces around the '12' to get it to match. So you're query would read as:

MATCH (a:pharma),(b:ind)
WHERE a.id = ' 12 ' AND b.id = '1'
CREATE (a)-[:has_indication]->(b)

Now, that'll get it to work - but it might be worth changing your model a bit, if the id is always an integer, I would change your creates to being:

CREATE ( p1:pharma { name: "Magnesium", id: 12 } ) 
CREATE ( p2:pharma { name: "Hyoscine Butylbromide", id: 22 } ) 
CREATE ( p3:pharma { name: "Propantheline Bromide", id: 23 } );

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:

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})

Basically I've removed the ' characters and used integers for id (and pdfk). The MATCH for this is:

MATCH (a:pharma),(b:ind)
WHERE a.id = 12 AND b.id = 1
CREATE (a)-[:has_ind]->(b)

And to check it works (aside from the message you get back):

MATCH (p:pharma),(i:ind) RETURN p,i

You'll see one is linked to another.

Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • I had recreated another graph database and also remodelled my cypher query with single quote (removed double quotes) also removed quotes for integer values. Then I run the cypher to create relation as you mentioned above, i get the same - Returned 0 rows in 702 ms ? Is there any thing to be done on properties files (auto-indexing is set to true) I have been trying this for the last couple of days and idn't found any break through... @Chris Skardon – Gopipuli Jan 10 '14 at 09:22
  • I had tried the tutorials in neo4j site (node created with no labels) and defining relationship with start syntax with node autoindexing it is working but my relations are not working !! Is there any thing like this I can do ? ( start n=node(12), m=node(1) create n<-[:HASIND]->m; ) .... – Gopipuli Jan 10 '14 at 09:25
  • Without the new `create` statements and the `match` it's difficult to say what you're changes require... Maybe you could add them to your question? – Charlotte Skardon Jan 10 '14 at 09:53
  • 1
    I've added an example which will *hopefully* help – Charlotte Skardon Jan 10 '14 at 10:01
  • ok let me check , and thank you for the quick response (helps) @Chris Skardon – Gopipuli Jan 10 '14 at 10:07
  • thank you very much !! its working One more thing, how can we create multiple relationship, I mean for other id's ? @Chris Skardon – Gopipuli Jan 10 '14 at 10:14
  • this is also working ( start n1=node:node_auto_index(id='12'),n2=node:node_auto_index(id='1') create n1-[:HAS_IND]->n2; ) so which is good to use in development ? @Chris Skardon Once agin Thank you very much for the wonderful help -:)) – Gopipuli Jan 10 '14 at 10:16
  • Well, those are really separate questions, you want to avoid any queries using `START` as that's older syntax. I would just use the `MATCH` clause you originally had. Multiple relationships would need to be another question - no answer would be formatted correctly in the comments, and what you want to do is unclear. – Charlotte Skardon Jan 10 '14 at 11:45
  • thank you @Chris Skardon Please check this link ( http://stackoverflow.com/questions/20986962/how-to-import-data-into-neo4j-neo4j-community-2-0-0-in-windows-7?rq=1 ) – Gopipuli Jan 10 '14 at 12:11