Npm ES library - how to do a upsert?

(Darin Hensley) #1

Using the ES node library.... how do I do a upsert? After reading documentation, I thought this would work but not having success. My goal is to insert a new document, if it already exists, then update it(or do nothing if there were no changes).

I get TypeError: Unable to build a path with those params. Supply at least index, type, id


 const upsertArtist = (artist) => {
  var doc = {
    scripted_upsert: true,
    script: {
      index: 'song',
      type: '_doc',
      body: {
        type: 'artist',
        artist: artist

    upsert: {},


  return client.update(doc);

(Thiago Souza) #2

The content of the doc.script needs to go into a nested body attribute. Check the docs for the proper syntax.

(system) #3

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