Npm ES library - how to do a upsert?

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

from:

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

    upsert: {},

  };

  return client.update(doc);
};

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

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