0

I had two set of nodes come under two different labels in neo4j(2V)

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

and my relationship code look like these for a single nodes from two set of labels

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

I want to know how can I write this as a batch query for other nodes too ? thanks in advance.


Iam using import.txt file with above code inside BEGIN COMMIT, then i use following code to create the database from command prompt

neo4jshell -path C:\progra~1\neo4j-community-2.0.0\data\drug11.db -config C:\progra~1\neo4j-community-2.0.0\conf\neo4j.properties -file C:\Users\admin\Downloads\import.txt

nodes will be created but not the relationship ?

Gopipuli
  • 393
  • 1
  • 12
  • 37
  • Please describe what you are trying to do in more detail. You want to create many relationships in one query? What relationships between which nodes? – jjaderberg Jan 14 '14 at 13:10
  • yes exactly @jjaderberg I want to create many relationship in single import.txt file. like MATCH (a:pharma),(b:ind) WHERE a.id = 23 AND b.id = 7 CREATE (a)-[:has_ind]->(b) MATCH (a:pharma),(b:ind) WHERE a.id = 22 AND b.id = 6 CREATE (a)-[:has_ind]->(b) like wise – Gopipuli Jan 15 '14 at 06:45

2 Answers2

1
Create ( p1:pharma { name: "Magnesium", id: 12 } )-[:has_ind]->( i1:ind { id: 1, name: 'Dyspepsia',  pdfk: '12'})

should work I think?

Ant P
  • 24,820
  • 5
  • 68
  • 105
Rik Van Bruggen
  • 379
  • 1
  • 3
  • let me check am uisng import (batch) function. @Rik Van Bruggen – Gopipuli Jan 15 '14 at 04:00
  • as a single cypher query its executing fine from browser, but when I put this in multiple times (changing the id's for relationship) this is not executing either from console browser or while attempting to import using command prompt @Rik Van Bruggen – Gopipuli Jan 18 '14 at 06:09
0

You would issue one of your queries at a time (what is the API you use?)

MATCH (a:pharma {id:12}),(b:ind {id:1})
CREATE (a)-[:has_ind]->(b)

With Parameters would be faster:

MATCH (a:pharma {id:{pharma_id}}),(b:ind {id:{ind_id}})
CREATE (a)-[:has_ind]->(b)

and then use the params: {"pharma_id":12,"ind_id":1} etc.

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • I was trying to import the above code using neo4jshell command, so it wont work when I put the above mentioned relationship cypher query. what it happen is it will import all nodes but relationship will not create ? @Michael Hunger – Gopipuli Jan 15 '14 at 03:55