How to add multiple tags (only if they dont exists) for multiple objects?

This doesn’t show how to update multiple tags (addUnique) for the same object?

I have “tag1”, “tag2” for object1
I have “tag1”, “tag2”, “tag3” for object2.
I have 1000 similar items. I’m programmatically generating these relationships
How to bulk add them?

The example from the doc shows that we can add a single tag for a single object. How to add multiple tags to the same object? Further update multiple such objects?


    index.partialUpdateObject({
      _tags: {
        value: 'MyTag',
        _operation: 'AddUnique'
      },
      objectID: 'myID'
    }, function(err, content) {
      console.log(content);
    });
...

Hello @johnsnow,

There is unfortunately no way to “add unique” multiple values to the same attribute of the same object inside the same operation.

As you pointed out, you can, however, do that using separate operations on the same object. You can even do that inside the same batch, so it would take only one round trip to the API:

index.batch([
  {
    objectID: 'myID',
    _tags: {
      value: 'Tag1',
      _operation: 'AddUnique'
    }
  },
  {
    objectID: 'myID',
    _tags: {
      value: 'Tag2',
      _operation: 'AddUnique'
    }
  }
], function(err, content) {
  console.log(content);
});