Api clients / JavaScript / V3 / Methods

Batch Synonyms | JavaScript API Client V3 (Deprecated)

This version of the JavaScript API client has been deprecated in favor of the latest version of the JavaScript API client.

Required API Key: any key with the editSettings ACL
Method signature
index.batchSynonyms(
  array synonyms,
  {
    forwardToReplicas: boolean,
    replaceExistingSynonyms: boolean
  },
  callback
)

About this method

Create or update multiple synonyms.

This method enables you to create or update one or more synonyms in a single call.

You can also recreate your entire set of synonyms by using the replaceExistingSynonyms parameter.

Note that each synonym object counts as a single indexing operation.

Examples

Batch synonyms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Batch synonyms,
// with replica forwarding and atomic replacement of existing synonyms

$index->saveSynonyms(
  [
    [
      "objectID" => "a-unique-identifier",
      "type" => "synonym",
      "synonyms" => ["car", "vehicle", "auto"]
    ],
    [
      "objectID" => "another-unique-identifier",
      "type" => "synonym",
      "synonyms" => ["street", "st"]
    ]
  ], [
    'forwardToReplicas' => true,
    'replaceExistingSynonyms' => true
  ]
);

Parameters

synonyms
type: list
Required

Array of synonym.

forwardToReplicas
type: boolean
default: false
optional

Sends synonyms to all replicas.

Without this parameter, or by setting it to false, the method will apply the change only to the specified index. If you want to forward your synonyms to replicas you will need to set this parameter to true.

replaceExistingSynonyms
type: boolean
default: false
optional

Forces the engine to replace all synonyms, using an atomic save.

Normally, to replace all synonyms on an index, you would first clear the synonyms, using clearAllSynonyms, and then create a new list. However, between the clear and the add, your index will have no synonyms. This is where replaceExistingSynonyms comes into play.

By adding this parameter, you do not need to use clearAllSynonyms, it’s done for you. This parameter tells the engine to delete all existing synonyms before recreating a new list from the synonyms listed in the current call. This is the only way to avoid having no synonyms, ensuring that your index will always provide a full list of synonyms to your end users.

Response

In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.

JSON format

1
2
3
4
{
  "updatedAt":"2013-01-18T15:33:13.556Z",
  "taskID": 678
}
updatedAt
string

Date at which the indexing job has been created.

taskID
integer

The taskID used with the waitTask method.

Did you find this page helpful?