This lets you execute multiple API calls through a single HTTP call, significantly improving performance for large insert and update operations.
The batch service expects an array of job descriptions as input, each job description describing an action to be performed via the normal server API.
This service is transactional. If any of the operations performed fails (returns a non-2xx HTTP status code), the transaction will be rolled back and all changes will be undone.
Each job description should contain a to
attribute, with a value
relative to the data API root (so http://localhost:7474/db/data/node becomes
just /node), and a method
attribute containing HTTP verb to use.
Optionally you may provide a body
attribute, and an id
attribute to
help you keep track of responses, although responses are guaranteed to be
returned in the same order the job descriptions are received.
The following figure outlines the different parts of the job descriptions:
Example request
POST
http://localhost:7474/db/data/batch
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
[ { "method" : "PUT", "to" : "/node/212/properties", "body" : { "age" : 1 }, "id" : 0 }, { "method" : "GET", "to" : "/node/212", "id" : 1 }, { "method" : "POST", "to" : "/node", "body" : { "age" : 1 }, "id" : 2 }, { "method" : "POST", "to" : "/node", "body" : { "age" : 1 }, "id" : 3 } ]
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "id" : 0, "from" : "/node/212/properties" }, { "id" : 1, "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/212/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/212/relationships/out", "traverse" : "http://localhost:7474/db/data/node/212/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/212/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/212/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/212/relationships/all", "self" : "http://localhost:7474/db/data/node/212", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/212/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/212/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/212/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/212/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/212/relationships", "data" : { "age" : 1 } }, "from" : "/node/212" }, { "id" : 2, "location" : "http://localhost:7474/db/data/node/213", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/213/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/213/relationships/out", "traverse" : "http://localhost:7474/db/data/node/213/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/213/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/213/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/213/relationships/all", "self" : "http://localhost:7474/db/data/node/213", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/213/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/213/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/213/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/213/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/213/relationships", "data" : { "age" : 1 } }, "from" : "/node" }, { "id" : 3, "location" : "http://localhost:7474/db/data/node/214", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/214/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/214/relationships/out", "traverse" : "http://localhost:7474/db/data/node/214/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/214/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/214/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/214/relationships/all", "self" : "http://localhost:7474/db/data/node/214", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/214/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/214/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/214/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/214/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/214/relationships", "data" : { "age" : 1 } }, "from" : "/node" } ]
The batch operation API allows you to refer to the URI returned from a created resource in subsequent job descriptions, within the same batch call.
Use the {[JOB ID]}
special syntax to inject URIs from created resources
into JSON strings in subsequent job descriptions.
Example request
POST
http://localhost:7474/db/data/batch
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
[ { "method" : "POST", "to" : "/node", "id" : 0, "body" : { "name" : "bob" } }, { "method" : "POST", "to" : "/node", "id" : 1, "body" : { "age" : 12 } }, { "method" : "POST", "to" : "{0}/relationships", "id" : 3, "body" : { "to" : "{1}", "data" : { "since" : "2010" }, "type" : "KNOWS" } }, { "method" : "POST", "to" : "/index/relationship/my_rels", "id" : 4, "body" : { "key" : "since", "value" : "2010", "uri" : "{3}" } } ]
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "id" : 0, "location" : "http://localhost:7474/db/data/node/205", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/205/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/205/relationships/out", "traverse" : "http://localhost:7474/db/data/node/205/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/205/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/205/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/205/relationships/all", "self" : "http://localhost:7474/db/data/node/205", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/205/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/205/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/205/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/205/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/205/relationships", "data" : { "name" : "bob" } }, "from" : "/node" }, { "id" : 1, "location" : "http://localhost:7474/db/data/node/206", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/206/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/206/relationships/out", "traverse" : "http://localhost:7474/db/data/node/206/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/206/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/206/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/206/relationships/all", "self" : "http://localhost:7474/db/data/node/206", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/206/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/206/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/206/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/206/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/206/relationships", "data" : { "age" : 12 } }, "from" : "/node" }, { "id" : 3, "location" : "http://localhost:7474/db/data/relationship/125", "body" : { "extensions" : { }, "start" : "http://localhost:7474/db/data/node/205", "property" : "http://localhost:7474/db/data/relationship/125/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/125", "properties" : "http://localhost:7474/db/data/relationship/125/properties", "type" : "KNOWS", "end" : "http://localhost:7474/db/data/node/206", "data" : { "since" : "2010" } }, "from" : "http://localhost:7474/db/data/node/205/relationships" }, { "id" : 4, "location" : "http://localhost:7474/db/data/index/relationship/my_rels/since/2010/125", "body" : { "extensions" : { }, "start" : "http://localhost:7474/db/data/node/205", "property" : "http://localhost:7474/db/data/relationship/125/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/125", "properties" : "http://localhost:7474/db/data/relationship/125/properties", "type" : "KNOWS", "end" : "http://localhost:7474/db/data/node/206", "data" : { "since" : "2010" }, "indexed" : "http://localhost:7474/db/data/index/relationship/my_rels/since/2010/125" }, "from" : "/index/relationship/my_rels" } ]
Example request
POST
http://localhost:7474/db/data/batch
Accept:
application/json
Content-Type:
application/json
X-Stream:
true
[ { "method" : "PUT", "to" : "/node/33/properties", "body" : { "age" : 1 }, "id" : 0 }, { "method" : "GET", "to" : "/node/33", "id" : 1 }, { "method" : "POST", "to" : "/node", "body" : { "age" : 1 }, "id" : 2 }, { "method" : "POST", "to" : "/node", "body" : { "age" : 1 }, "id" : 3 } ]
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "id" : 0, "from" : "/node/33/properties", "body" : null, "status" : 204 }, { "id" : 1, "from" : "/node/33", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/33/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/33/relationships/out", "traverse" : "http://localhost:7474/db/data/node/33/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/33/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/33/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/33/relationships/all", "self" : "http://localhost:7474/db/data/node/33", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/33/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/33/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/33/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/33/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/33/relationships", "data" : { "age" : 1 } }, "status" : 200 }, { "id" : 2, "from" : "/node", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/34/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/34/relationships/out", "traverse" : "http://localhost:7474/db/data/node/34/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/34/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/34/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/34/relationships/all", "self" : "http://localhost:7474/db/data/node/34", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/34/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/34/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/34/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/34/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/34/relationships", "data" : { "age" : 1 } }, "location" : "http://localhost:7474/db/data/node/34", "status" : 201 }, { "id" : 3, "from" : "/node", "body" : { "extensions" : { }, "paged_traverse" : "http://localhost:7474/db/data/node/35/paged/traverse/{returnType}{?pageSize,leaseTime}", "outgoing_relationships" : "http://localhost:7474/db/data/node/35/relationships/out", "traverse" : "http://localhost:7474/db/data/node/35/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/35/relationships/all/{-list|&|types}", "property" : "http://localhost:7474/db/data/node/35/properties/{key}", "all_relationships" : "http://localhost:7474/db/data/node/35/relationships/all", "self" : "http://localhost:7474/db/data/node/35", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/35/relationships/out/{-list|&|types}", "properties" : "http://localhost:7474/db/data/node/35/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/35/relationships/in", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/35/relationships/in/{-list|&|types}", "create_relationship" : "http://localhost:7474/db/data/node/35/relationships", "data" : { "age" : 1 } }, "location" : "http://localhost:7474/db/data/node/35", "status" : 201 } ]
Copyright © 2013 Neo Technology