@@ -346,5 +346,137 @@ POST _bulk
346
346
{ "update" : {"_id" : "4", "_index" : "index1"} }
347
347
{ "doc" : {"field" : "value"}, "_source": true}
348
348
--------------------------------------------------
349
+
350
+ [discrete]
351
+ [[bulk-failures-ex]]
352
+ ===== Example with failed actions
353
+
354
+ The following bulk API request includes operations that update non-existent
355
+ documents.
356
+
357
+ [source,console]
358
+ ----
359
+ POST /_bulk
360
+ { "update": {"_id": "5", "_index": "index1"} }
361
+ { "doc": {"my_field": "foo"} }
362
+ { "update": {"_id": "6", "_index": "index1"} }
363
+ { "doc": {"my_field": "foo"} }
364
+ { "create": {"_id": "7", "_index": "index1"} }
365
+ { "my_field": "foo" }
366
+ ----
367
+
368
+ Because these operations cannot complete successfully, the API returns a
369
+ response with an `errors` flag of `true`.
370
+
371
+ The response also includes an `error` object for any failed operations. The
372
+ `error` object contains additional information about the failure, such as the
373
+ error type and reason.
374
+
375
+ [source,console-result]
376
+ ----
377
+ {
378
+ "took": 486,
379
+ "errors": true,
380
+ "items": [
381
+ {
382
+ "update": {
383
+ "_index": "index1",
384
+ "_type" : "_doc",
385
+ "_id": "5",
386
+ "status": 404,
387
+ "error": {
388
+ "type": "document_missing_exception",
389
+ "reason": "[_doc][5]: document missing",
390
+ "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
391
+ "shard": "0",
392
+ "index": "index1"
393
+ }
394
+ }
395
+ },
396
+ {
397
+ "update": {
398
+ "_index": "index1",
399
+ "_type" : "_doc",
400
+ "_id": "6",
401
+ "status": 404,
402
+ "error": {
403
+ "type": "document_missing_exception",
404
+ "reason": "[_doc][6]: document missing",
405
+ "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
406
+ "shard": "0",
407
+ "index": "index1"
408
+ }
409
+ }
410
+ },
411
+ {
412
+ "create": {
413
+ "_index": "index1",
414
+ "_type" : "_doc",
415
+ "_id": "7",
416
+ "_version": 1,
417
+ "result": "created",
418
+ "_shards": {
419
+ "total": 2,
420
+ "successful": 1,
421
+ "failed": 0
422
+ },
423
+ "_seq_no": 0,
424
+ "_primary_term": 1,
425
+ "status": 201
426
+ }
427
+ }
428
+ ]
429
+ }
430
+ ----
431
+ // TESTRESPONSE[s/"took": 486/"took": $body.took/]
432
+ // TESTRESPONSE[s/"_seq_no": 0/"_seq_no": $body.items.2.create._seq_no/]
433
+ // TESTRESPONSE[s/"index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA"/"index_uuid": $body.$_path/]
434
+
435
+ To return only information about failed operations, use the
436
+ <<common-options-response-filtering,`filter_path`>> query parameter with an
437
+ argument of `items.*.error`.
438
+
439
+ [source,console]
440
+ ----
441
+ POST /_bulk?filter_path=items.*.error
442
+ { "update": {"_id": "5", "_index": "index1"} }
443
+ { "doc": {"my_field": "baz"} }
444
+ { "update": {"_id": "6", "_index": "index1"} }
445
+ { "doc": {"my_field": "baz"} }
446
+ { "update": {"_id": "7", "_index": "index1"} }
447
+ { "doc": {"my_field": "baz"} }
448
+ ----
349
449
// TEST[continued]
350
450
451
+ The API returns the following result.
452
+
453
+ [source,console-result]
454
+ ----
455
+ {
456
+ "items": [
457
+ {
458
+ "update": {
459
+ "error": {
460
+ "type": "document_missing_exception",
461
+ "reason": "[_doc][5]: document missing",
462
+ "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
463
+ "shard": "0",
464
+ "index": "index1"
465
+ }
466
+ }
467
+ },
468
+ {
469
+ "update": {
470
+ "error": {
471
+ "type": "document_missing_exception",
472
+ "reason": "[_doc][6]: document missing",
473
+ "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
474
+ "shard": "0",
475
+ "index": "index1"
476
+ }
477
+ }
478
+ }
479
+ ]
480
+ }
481
+ ----
482
+ // TESTRESPONSE[s/"index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA"/"index_uuid": $body.$_path/]
0 commit comments