// This file is autogenerated, DO NOT EDIT
// Use `node scripts/generate-docs-examples.mjs` to generate the docs examples

[source, js]
----
const response = await client.update({
  index: "test",
  id: 1,
  scripted_upsert: true,
  script: {
    source:
      "\n      if ( ctx.op == 'create' ) {\n        ctx._source.counter = params.count\n      } else {\n        ctx._source.counter += params.count\n      }\n    ",
    params: {
      count: 4,
    },
  },
  upsert: {},
});
console.log(response);
----
