# Node-js: client.helpers.bulk() : get errors on fail?

**URL:** <https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200>\
**Category:** OpenSearch Client Libraries\
**Tags:** opensearch-js\
**Created:** [May 4, 2023, 1:41pm UTC](https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200 "2023-05-04T13:41:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tegatoo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/tegatoo/32/5456_2.png) [@Tegatoo](https://forum.opensearch.org/u/Tegatoo)\
**Post date:** [May 4, 2023, 1:41pm UTC](https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200/1 "2023-05-04T13:41:29Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser): 2.7.x

**Describe the issue** :

> **[Helper methods](https://opensearch.org/docs/latest/clients/javascript/helpers/)**
>
> Helper methods

Consider a code:

```auto
   try {
      var response = await this.client.helpers.bulk({
        datasource: upserts,
        onDocument(upsert) {
          const { indexName, docId, routing, upsertDoc } = upsert;
          return [
            {
              update: { _index: indexName, _id: docId, routing },
            },
            { doc: upsertDoc, doc_as_upsert: true },
          ];
        },
      });

```

I get reply:

```auto
[1683207618971] DEBUG (1547491 on localhost.localdomain): kaijs:opensearch [I] Result of bulk action: {
  kaijs:opensearch total: 100,
  kaijs:opensearch failed: 54,
  kaijs:opensearch retry: 0,
  kaijs:opensearch successful: 46,
  kaijs:opensearch noop: 0,
  kaijs:opensearch time: 1200,
  kaijs:opensearch bytes: 430884,
  kaijs:opensearch aborted: false
  kaijs:opensearch } +1s

```

How to get any insight why bulk operation has failed ?

Retry doesn’t help.

---

<div class="post-metadata">

**Author:** ![Tegatoo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/tegatoo/32/5456_2.png) [@Tegatoo](https://forum.opensearch.org/u/Tegatoo)\
**Post date:** [May 4, 2023, 2:39pm UTC](https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200/2 "2023-05-04T14:39:13Z")

</div>

Solved with direct call client.bulk:

```auto
try {
      const body = _.flatMap(upserts, (upsert) => [
        {
          update: {
            _index: upsert.indexName,
            _id: upsert.docId,
            routing: upsert.routing,
          },
        },
        { doc: upsert.upsertDoc, doc_as_upsert: true },
      ]);
      const { body: response } = await this.client.bulk({ body });
      this.log('Result of bulk action: %O', printify(response));
      assert(response.errors === false, 'Error in bulk operation.');
    } catch (err) {

```

---

<div class="post-metadata">

**Author:** ![wbeckler](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@wbeckler](https://forum.opensearch.org/u/wbeckler)\
**Post date:** [May 4, 2023, 5:02pm UTC](https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200/3 "2023-05-04T17:02:37Z")

</div>

Would you consider submitting this as a documentation improvement?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)\
**Post date:** [July 3, 2023, 5:03pm UTC](https://forum.opensearch.org/t/node-js-client-helpers-bulk-get-errors-on-fail/14200/4 "2023-07-03T17:03:24Z")

</div>

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