> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Save synonyms

> Create or update multiple synonyms.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Create or replace synonyms" href="/doc/libraries/sdk/methods/search/save-synonyms" />

**Required ACL:** `editSettings`

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

You can also **recreate your entire set of synonyms** by using the [`replaceExistingSynonyms`](/doc/libraries/sdk/v1/methods/save-synonyms#param-replace-existing-synonyms) parameter.

<Info>
  Each synonym object counts as a single [indexing operation](https://support.algolia.com/hc/en-us/articles/17245378392977-How-does-Algolia-count-records-and-operations).
</Info>

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  List<Synonym> synonyms = new List<Synonym>
  {
      new Synonym
      {
        ObjectID = "synonymID1",
        Type = "synonym",
        Synonyms = new List<string> { "car", "vehicle", "auto" }
      },
      new Synonym
      {
        ObjectID = "synonymID2",
        Type = "synonym",
        Synonyms = new List<string> { "street", "st" }
      }
  };

  index.SaveSynonyms(synonyms, forwardToreplicas: true, replaceExistingSynonyms: true);

  // Asynchronous
  await index.SaveSynonymsAsync(synonyms, forwardToreplicas: true, replaceExistingSynonyms: true);
  ```

  ```go Go theme={"system"}
  opts := []interface{}{
  	opt.ForwardToReplicas(true),
  	opt.ReplaceExistingSynonyms(true),
  }

  synonyms := []search.Synonym{
  	search.NewRegularSynonym("synonymID1", "car", "vehicle", "auto"),
  	search.NewRegularSynonym("synonymID2", "street", "st"),
  }

  res, err := index.SaveSynonyms(synonyms, opts...)
  ```

  ```java Java theme={"system"}
  // Batch synonyms, with replica forwarding
  // and atomic replacement of existing synonyms

  boolean forwardToReplicas = true;
  boolean replaceExistingSynonyms = true;

  List<Synonym> synonyms = Arrays.asList(
      new Synonym()
        .setObjectID("synonymID1")
        .setSynonyms(Arrays.asList("car", "vehicle", "auto")),
      new Synonym()
        .setObjectID("synonymID2")
        .setSynonyms(Arrays.asList("street", "st")));

  index.saveSynonyms(synonyms, forwardToReplicas, replaceExistingSynonyms);

  // Asynchronous
  index.saveSynonymsAsync(synonyms, forwardToReplicas, replaceExistingSynonyms);
  ```

  ```js JavaScript theme={"system"}
  // Batch synonyms, with replica forwarding and atomic replacement of existing synonyms
  const synonyms = [{
    objectID: 'synonymID1',
    type: 'synonym',
    synonyms: ['car', 'vehicle', 'auto']
  }, {
    objectID: 'synonymID2',
    type: 'synonym',
    synonyms: ['street', 'st']
  }];

  index.saveSynonyms(synonyms, {
    forwardToReplicas: true,
    replaceExistingSynonyms: true
  }).then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val synonyms = listOf(
      Synonym.MultiWay(
          objectID = ObjectID("myID1"),
          synonyms = listOf("car", "vehicle", "auto")
      ),
      Synonym.MultiWay(
          objectID = ObjectID("myID2"),
          synonyms = listOf("street", "st")
      )
  )
  index.saveSynonyms(synonyms, forwardToReplicas = true, clearExistingSynonyms = true)
  ```

  ```php PHP theme={"system"}
  // Batch synonyms,
  // with replica forwarding and atomic replacement of existing synonyms

  $index->saveSynonyms(
    [
      [
        "objectID" => "synonymID1",
        "type" => "synonym",
        "synonyms" => ["car", "vehicle", "auto"]
      ],
      [
        "objectID" => "synonymID2",
        "type" => "synonym",
        "synonyms" => ["street", "st"]
      ]
    ], [
      'forwardToReplicas' => true,
      'replaceExistingSynonyms' => true
    ]
  );
  ```

  ```python Python theme={"system"}
  # Batch synonyms, with replica forwarding and atomic replacement of existing synonyms
  index.save_synonyms(
      [
          {
              'objectID': 'synonymID1',
              'type': 'synonym',
              'synonyms': ['car', 'vehicle', 'auto']
          },
          {
              'objectID': 'synonymID2',
              'type': 'synonym',
              'synonyms': ['street', 'st']
          }
      ],
      {
          'forwardToReplicas': True,
          'replaceExistingSynonyms': True
      }
  )
  ```

  ```ruby Ruby theme={"system"}
  # Batch synonyms, with replica forwarding and atomic replacement of existing synonyms
  index.save_synonyms([{
    objectID: 'synonymID1',
    type: 'synonym',
    synonyms: ['car', 'vehicle', 'auto']
  }, {
    objectID: 'synonymID2',
    type: 'synonym',
    synonyms: ['street', 'st']
  }], { forwardToReplicas: true, replaceExistingSynonyms: true })
  ```

  ```scala Scala theme={"system"}
  // Batch synonyms, with replica forwarding
  // and atomic replacement of existing synonyms
  client.execute {
    save synonyms Seq(
      Synonym(
        "synonymID1",
        Seq("car", "vehicle", "auto")
      ),
      Synonym(
        "synonymID2",
        Seq("street", "st")
      )
    ) inIndex "index_name" and forwardToReplicas and replaceExistingSynonyms
  }
  ```

  ```swift Swift theme={"system"}
  let synonyms: [Synonym] = [
    .multiWay(objectID: "synonymID1", synonyms: ["car", "vehicle", "auto"]),
    .multiWay(objectID: "synonymID2", synonyms: ["street", "st"])
  ]

  index.saveSynonyms(synonyms, forwardToReplicas: true, replaceExistingSynonyms: false) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="synonyms" type="synonym[]" required>
  List of synonyms to add or update.
  For details about the expected shape of the synonym object,
  see [`synonym`](/doc/libraries/sdk/v1/methods/save-synonym#param-synonym).
</ParamField>

<ParamField body="forwardToReplicas" type="boolean" default={false}>
  Whether to add synonyms to all replica indices.
</ParamField>

<ParamField body="replaceExistingSynonyms" type="boolean" default={false}>
  Whether to delete all synonyms before adding new ones.

  Use this option if you want to replace your existing synonyms with the ones provided with this method.
</ParamField>

## Response

<ResponseField name="taskID" type="integer">
  The task ID used with the [`waitTask`](/doc/libraries/sdk/v1/methods/wait-task) method.
</ResponseField>

<ResponseField name="updatedAt" type="string">
  Date at which the indexing job has been created.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "updatedAt":"2013-01-18T15:33:13.556Z",
  "taskID": 678
}
```
