6.10. Batch operations

6.10.1. Execute multiple operations in batch
6.10.2. Refer to items created earlier in the same batch job
[Caution]Caution

Batch support is currently experimental. Expect this part of the API to change.

6.10.1. Execute multiple operations in batch

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 path attribute, with a value relative to the data API root (so http://localhost/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
  • Content-Type: application/json
[
  {
    "method":"PUT",
    "to":"/node/0/properties",
    "body":{
      "age":1
    },
    "id":0
  },
  {
    "method":"GET",
    "to":"/node/0",
    "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
[{"id":0,"from":"/node/0/properties"},{"id":1,"body":{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/0/relationships/out",
  "data" : {
    "age" : 1
  },
  "traverse" : "http://localhost:7474/db/data/node/0/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/0/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/0",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/0/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/0/relationships/in",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "connected_nodes" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/0/connected_nodes",
      "pathToReference" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/0/pathToReference",
      "getThisNodeOrById" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/0/getThisNodeOrById",
      "createRelationships" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/0/createRelationships",
      "getRelationshipsBetween" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/0/getRelationshipsBetween"
    },
    "GraphCloner" : {
      "clonedSubgraph" : "http://localhost:7474/db/data/ext/GraphCloner/node/0/clonedSubgraph"
    }
  },
  "create_relationship" : "http://localhost:7474/db/data/node/0/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/0/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/0/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/in/{-list|&|types}"
},"from":"/node/0"},{"id":2,"location":"http://localhost:7474/db/data/node/3","body":{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/3/relationships/out",
  "data" : {
    "age" : 1
  },
  "traverse" : "http://localhost:7474/db/data/node/3/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/3/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/3/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/3",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/3/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/3/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/3/relationships/in",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "connected_nodes" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/3/connected_nodes",
      "pathToReference" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/3/pathToReference",
      "getThisNodeOrById" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/3/getThisNodeOrById",
      "createRelationships" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/3/createRelationships",
      "getRelationshipsBetween" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/3/getRelationshipsBetween"
    },
    "GraphCloner" : {
      "clonedSubgraph" : "http://localhost:7474/db/data/ext/GraphCloner/node/3/clonedSubgraph"
    }
  },
  "create_relationship" : "http://localhost:7474/db/data/node/3/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/3/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/3/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/3/relationships/in/{-list|&|types}"
},"from":"/node"},{"id":3,"location":"http://localhost:7474/db/data/node/4","body":{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/4/relationships/out",
  "data" : {
    "age" : 1
  },
  "traverse" : "http://localhost:7474/db/data/node/4/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/4/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/4",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/4/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/4/relationships/in",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "connected_nodes" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/4/connected_nodes",
      "pathToReference" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/4/pathToReference",
      "getThisNodeOrById" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/4/getThisNodeOrById",
      "createRelationships" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/4/createRelationships",
      "getRelationshipsBetween" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/4/getRelationshipsBetween"
    },
    "GraphCloner" : {
      "clonedSubgraph" : "http://localhost:7474/db/data/ext/GraphCloner/node/4/clonedSubgraph"
    }
  },
  "create_relationship" : "http://localhost:7474/db/data/node/4/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/4/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/4/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/4/relationships/in/{-list|&|types}"
},"from":"/node"}]

6.10.2. Refer to items created earlier in the same batch job

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
  • Content-Type: application/json
[
  {
    "method":"POST",
    "to":"/node",
    "id":0,
    "body":{
      "age":1
    }
  },
  {
    "method":"POST",
    "to":"/node",
    "id":1,
    "body":{
      "age":12
    }
  },
  {
    "method":"POST",
    "to":"{0}/relationships",
    "id":3,
    "body":{
      "to":"{1}",
      "data":{
        "name":"bob"
      },
      "type":"KNOWS"
    }
  },
  {
    "method":"POST",
    "to":"/index/relationship/my_rels/name/bob",
    "id":4,
    "body":"{3}"
  }
]

Example response

  • 200: OK
  • Content-Type: application/json
[{"id":0,"location":"http://localhost:7474/db/data/node/7","body":{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/7/relationships/out",
  "data" : {
    "age" : 1
  },
  "traverse" : "http://localhost:7474/db/data/node/7/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/7/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/7",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/7/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/7/relationships/in",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "connected_nodes" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/7/connected_nodes",
      "pathToReference" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/7/pathToReference",
      "getThisNodeOrById" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/7/getThisNodeOrById",
      "createRelationships" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/7/createRelationships",
      "getRelationshipsBetween" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/7/getRelationshipsBetween"
    },
    "GraphCloner" : {
      "clonedSubgraph" : "http://localhost:7474/db/data/ext/GraphCloner/node/7/clonedSubgraph"
    }
  },
  "create_relationship" : "http://localhost:7474/db/data/node/7/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/7/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/7/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/7/relationships/in/{-list|&|types}"
},"from":"/node"},{"id":1,"location":"http://localhost:7474/db/data/node/8","body":{
  "outgoing_relationships" : "http://localhost:7474/db/data/node/8/relationships/out",
  "data" : {
    "age" : 12
  },
  "traverse" : "http://localhost:7474/db/data/node/8/traverse/{returnType}",
  "all_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/all/{-list|&|types}",
  "property" : "http://localhost:7474/db/data/node/8/properties/{key}",
  "self" : "http://localhost:7474/db/data/node/8",
  "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/out/{-list|&|types}",
  "properties" : "http://localhost:7474/db/data/node/8/properties",
  "incoming_relationships" : "http://localhost:7474/db/data/node/8/relationships/in",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "connected_nodes" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/8/connected_nodes",
      "pathToReference" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/8/pathToReference",
      "getThisNodeOrById" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/8/getThisNodeOrById",
      "createRelationships" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/8/createRelationships",
      "getRelationshipsBetween" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/node/8/getRelationshipsBetween"
    },
    "GraphCloner" : {
      "clonedSubgraph" : "http://localhost:7474/db/data/ext/GraphCloner/node/8/clonedSubgraph"
    }
  },
  "create_relationship" : "http://localhost:7474/db/data/node/8/relationships",
  "paged_traverse" : "http://localhost:7474/db/data/node/8/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://localhost:7474/db/data/node/8/relationships/all",
  "incoming_typed_relationships" : "http://localhost:7474/db/data/node/8/relationships/in/{-list|&|types}"
},"from":"/node"},{"id":3,"location":"http://localhost:7474/db/data/relationship/1","body":{
  "start" : "http://localhost:7474/db/data/node/7",
  "data" : {
    "name" : "bob"
  },
  "self" : "http://localhost:7474/db/data/relationship/1",
  "property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/1/properties",
  "type" : "KNOWS",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "methodOnRelationship" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/relationship/1/methodOnRelationship"
    }
  },
  "end" : "http://localhost:7474/db/data/node/8"
},"from":"http://localhost:7474/db/data/node/7/relationships"},{"id":4,"location":"http://localhost:7474/db/data/index/relationship/my_rels/name/bob/1","body":{
  "indexed" : "http://localhost:7474/db/data/index/relationship/my_rels/name/bob/1",
  "start" : "http://localhost:7474/db/data/node/7",
  "data" : {
    "name" : "bob"
  },
  "self" : "http://localhost:7474/db/data/relationship/1",
  "property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/1/properties",
  "type" : "KNOWS",
  "extensions" : {
    "FunctionalTestPlugin" : {
      "methodOnRelationship" : "http://localhost:7474/db/data/ext/FunctionalTestPlugin/relationship/1/methodOnRelationship"
    }
  },
  "end" : "http://localhost:7474/db/data/node/8"
},"from":"/index/relationship/my_rels/name/bob"}]