# Get the only failed document response in Bulk API Elasticsearch

**URL:** <https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873>\
**Category:** Elasticsearch\
**Created:** [April 20, 2018, 12:19pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873 "2018-04-20T12:19:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashishtiwari1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishtiwari1993/32/135241_2.png) [@ashishtiwari1993](https://discuss.elastic.co/u/ashishtiwari1993)\
**Post date:** [April 20, 2018, 12:19pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/1 "2018-04-20T12:19:01Z")

</div>

I am struggling with Bulk API. I am sending 100 request (index, update) in every Bulk request. It gives me response with status of each request. Suppose my 97th request got fail, I have to make it loop to find the particular error document. I think its not optimize way. If i am sending more number of Bulk request, It makes my process slow. Is there any way where i will get only failed document or count of fail/success document in response? I am using php-elasticsearch SDK .

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 27, 2018, 1:50pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/2 "2018-04-27T13:50:30Z")

</div>

There is a top-level "errors" field you can check. If that field is false, there are no errors and you don't have to loop through the documents. More details here: [https://github.com/elastic/elasticsearch/issues/25156#issuecomment-307806954](https://github.com/elastic/elasticsearch/issues/25156#issuecomment-307806954)

E.g.

```auto
$responses = $client->bulk($params);
if (isset($responses['errors']) === true && $responses['errors'] === true) {
    echo "There was one or more errors in the bulk response.\n\n";
}
foreach ($responses['items'] as $item) {
    echo "Status: {$item['create']['status']}\n";
    if (isset($item['create']['error']) === true) {
        print_r($item['create']['error']);
    }
    echo "\n";
}

```

---

<div class="post-metadata">

**Author:** ![ashishtiwari1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishtiwari1993/32/135241_2.png) [@ashishtiwari1993](https://discuss.elastic.co/u/ashishtiwari1993)\
**Post date:** [April 28, 2018, 1:54pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/3 "2018-04-28T13:54:35Z")

</div>

Its good for small bulk size what if my bulk size is much like 5000 or more it makes my process slow. I guess this is not optimize way to solve large bulk size. It will unnecessary iterate successful records. I suggest ES should enhance response format.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 30, 2018, 2:57pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/4 "2018-04-30T14:57:56Z")

</div>

It's been discussed before ([here](https://github.com/elastic/elasticsearch/issues/2661) and [here](https://github.com/elastic/elasticsearch/pull/17932)) but ultimately we've decided a change isn't worth it.

It's trivial for a client to iterate over the response and the bulk response is very compressible, so even large responses have pretty low impact on network transfer speed. If your code is slow to process the bulk it may be an issue with your application code. Iterating over an array of a few thousand items should be very fast no matter the language (even in PHP).

---

<div class="post-metadata">

**Author:** ![ashishtiwari1993](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishtiwari1993/32/135241_2.png) [@ashishtiwari1993](https://discuss.elastic.co/u/ashishtiwari1993)\
**Post date:** [May 5, 2018, 5:07pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/5 "2018-05-05T17:07:28Z")

</div>

Yes but I think when bulk size high it can cause speed issue.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 2, 2018, 5:07pm UTC](https://discuss.elastic.co/t/get-the-only-failed-document-response-in-bulk-api-elasticsearch/128873/6 "2018-06-02T17:07:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
