multiple queries in one cypher statement over rest

1,472 views
Skip to first unread message

shahar taite

unread,
Sep 11, 2013, 4:47:10 AM9/11/13
to ne...@googlegroups.com
Hey guys,
i'm creating a generator for cypher queries, and i would like to be able to send a bunch of queries in one cypher statement throught the rest API but using the cypher address(http://localhost:7474/db/data/cypher)
is there any way of diffrentiating the different queries in one cypher so i can just send it as one piece to http://localhost:7474/db/data/cypher and it will run one after the other?


example for such query:

Create(n1{Type:'Person',Lname:'Taite',Fname:'Shahar'})
Start A3=node(*), B3=node(*) 
Where A3.Type='Person'
and A3.Lname='Taite' 
and A3.Fname='Shahar' 
and B3.Type='Term' 
and B3.Text='Software' 
Create(A3)-[:Knows {}]->(B3)

Michael Hunger

unread,
Sep 11, 2013, 5:03:04 AM9/11/13
to ne...@googlegroups.com
You can already combine your two queries into one:

Create(n1{Type:'Person',Lname:'Taite',Fname:'Shahar'})
    WITH n1 
Start  B3=node(*) 
and B3.Type='Term' 
and B3.Text='Software' 
Create(n1)-[:Knows {}]->(B3)

You would also want to try an index lookup for the B3 node instead of scanning the whole database.
Either with a start clause too (1.9) or with a label based index in Neo4j 2.0 match B3:Term where B3.Text='Software' (index would be: create index on :Term(text); )

Which Neo4j version are you using?

With Neo4j 2.0 there is the transactional http endpoint which allows that.

In Neo4j 1.9 you can use the batch-rest-operations.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

shahar taite

unread,
Sep 16, 2013, 4:29:37 AM9/16/13
to ne...@googlegroups.com
i'm using Neo4j 1.9.2
i checked out the batch-rest-operations but i would like to stick to Cypher queries , is there any option for batch operations using cypher queries?
thanks

Michael Hunger

unread,
Sep 16, 2013, 4:39:44 AM9/16/13
to ne...@googlegroups.com
Sure,

works the same way.

Just use /db/data/cypher as "to" and "body" : { "query" : "start ...", "params" : {"param1","value1"} }

HTH

Michael

shahar taite

unread,
Sep 16, 2013, 4:44:19 AM9/16/13
to ne...@googlegroups.com
oh and can you point me to a link of how to do the "start clause too" you were mentioning?
thanks

Michael Hunger

unread,
Sep 16, 2013, 4:49:21 AM9/16/13
to ne...@googlegroups.com

shahar taite

unread,
Sep 16, 2013, 4:52:03 AM9/16/13
to ne...@googlegroups.com
oh ok i got what you meant.
great help Michael 
thanks so much
great to see there is help here when i need it

Michael Hunger

unread,
Sep 16, 2013, 5:00:41 AM9/16/13
to ne...@googlegroups.com
You're welcome,

you can also try the batching cypher statements in the HTTP shell

just use something like this


POST /db/data/batch [{"id":0, "to":"/db/data/cypher", "method":"POST", "body" : { "query" : "start n=node:node_auto_index(name={param1}) return n", "params" : {"param1":"value1"} }}]
Reply all
Reply to author
Forward
0 new messages