# Elastic Search Update Operation not working when using nodejs client

**URL:** <https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 4, 2022, 6:50pm UTC](https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811 "2022-10-04T18:50:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atul\_Joshi1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_joshi1/32/98606_2.png) [@Atul\_Joshi1](https://discuss.elastic.co/u/Atul_Joshi1)\
**Post date:** [October 4, 2022, 6:50pm UTC](https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811/1 "2022-10-04T18:50:34Z")

</div>

I am updating the existing document in Elasticsearch by below update query.

```auto
  const result = await client.update({
          index,
          id,
          body: {
            script: {
              lang: "painless",
              source: "ctx._source = params.customerDetailsObj",
              params: {
                customerDetailsObj: item
              }
            }
          }
        });

```

where item has below structure -

```auto
    customerDetails: {
        details,
        metadata
    }

```

and client is `elasticsearch` client  
id and index are correct values where id belongs to already existing id in Elasticsearch

` const { Client } = require("@elastic/elasticsearch");`

and already saved document structure is below -

```auto

      {
        "_index" : "customerdetailsreport",
        "_type" : "_doc",
        "_id" : "cu-qo4MBxhUIUIg_lZUJ",
        "_score" : 12.078913,
        "_source" : {
          "customerDetails" : {
            "details" : {
              "id" : "1234567",
              "name" : "Atul Joshi",
            },
            "metadata" : {
              "id" : "1234567"
            }
          }
        }
      }

```

The issue I am facing is , after update operation , existing item is not updated but a new entry is created

So , In Elasticsearch I find two documents with different \_id meaning two different entries are created

Can anybody please help what I am missing here ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 4, 2022, 7:02pm UTC](https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811/2 "2022-10-04T19:02:42Z")

</div>

> [@Atul\_Joshi1](#):
>
> ```auto
> const result = await client.update({
> index,
> id,
> body: {
> 
> ```

What is the `id` parameter set to here? If you e.g. wanted to update the document you showed, it should be set to `cu-qo4MBxhUIUIg_lZUJ`.

---

<div class="post-metadata">

**Author:** ![Atul\_Joshi1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_joshi1/32/98606_2.png) [@Atul\_Joshi1](https://discuss.elastic.co/u/Atul_Joshi1)\
**Post date:** [October 4, 2022, 7:17pm UTC](https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811/3 "2022-10-04T19:17:33Z")

</div>

Yes , the id is exactly the same . I cross checked that

---

<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:** [November 1, 2022, 7:17pm UTC](https://discuss.elastic.co/t/elastic-search-update-operation-not-working-when-using-nodejs-client/315811/4 "2022-11-01T19:17:57Z")

</div>

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