Elastic Search Update Operation not working when using nodejs client

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

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

where item has below structure -

    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 -


      {
        "_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 ?

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.

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

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