json/bulk¶
The json/bulk
endpoint allows you to perform several insert, update or delete operations in a single call. This endpoint only works with data that has Content-Type
set to application/x-ndjson
. The data itself should be formatted as a newline-delimited json (NDJSON). Basically it means that each line should contain exactly one json statement and end with a newline \n
and maybe a \r
.
Example:
{ "insert" : { "index" : "test", "id" : 1, "doc": { "gid" : 10, "content" : "doc one" } } }
{ "insert" : { "index" : "test", "id" : 2, "doc": { "gid" : 20, "content" : "doc two" } } }
This inserts two documents to index test
. Each statement starts with an action type (in this case, insert
). Here’s a list of the supported actions:
insert
: Inserts a document. Syntax is the same as injson/insert
.create
: a synonym forinsert
replace
: Replaces a document. Syntax is the same as injson/replace
.index
: a synonym forreplace
update
: Updates a document. Syntax is the same as injson/update
.delete
: Deletes a document. Syntax is the same as injson/delete
.
Updates by query and deletes by query are also supported.
Example:
{ "update" : { "index" : "test", "doc": { "tag" : 1000 }, "query": { "range": { "price": { "gte": 1000 } } } } }
{ "delete" : { "index" : "test", "query": { "range": { "price": { "lt": 1000 } } } } }
Note that the bulk operation stops at the first query that results in an error.