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

# Replace all synonyms

> Push a new set of synonyms and erase all previous ones.

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, like `replaceAllObjects`, guarantees zero downtime.

All existing synonyms are deleted and replaced with the new ones, in a single, atomic operation.

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  SearchClient client = new SearchClient("YourApplicationID", "YourWriteAPIKey");
  SearchIndex index = client.InitIndex("INDEX_NAME");

  List<Synonym> synonyms = /* Fetch your synonyms */

  index.ReplaceAllSynonyms(synonyms);

  // Or if you want to also replace synonyms on replicas
  index.ReplaceAllSynonyms(synonyms, forwardToReplicas: true);

  // Asynchronous
  await index.ReplaceAllSynonymsAsync(synonyms, forwardToReplicas: true);
  ```

  ```go Go theme={"system"}
  package main

  import (
      "github.com/algolia/algoliasearch-client-go/v3/algolia/search"
  )

  func main() {
      client := search.NewClient("YourApplicationID", "YourAdminKey")
      index := client.InitIndex("INDEX_NAME")

      synonyms := []search.Synonym{ /* Fetch your synonyms */ }

      res, err := index.ReplaceAllSynonyms(synonyms)
  }
  ```

  ```java Java theme={"system"}
  SearchClient client =
  DefaultSearchClient.create("YourApplicationID", "YourWriteAPIKey");

  SearchIndex index = client.initIndex("INDEX_NAME");

  List<Synonym> synonyms = /* Fetch your synonyms */

  index.replaceAllSynonyms(synonyms);

  // Or if you want to also replace synonyms on replicas
  index.replaceAllSynonyms(synonyms, true);

  // Async
  index.replaceAllSynonymsAsync(synonyms);
  index.replaceAllSynonymsAsync(synonyms, true);
  ```

  ```js JavaScript theme={"system"}
  const client = algoliasearch('YourApplicationID', 'YourWriteAPIKey');

  const synonyms = [/* Fetch your synonyms */];

  const index = client.initIndex('INDEX_NAME');

  index.replaceAllSynonyms(synonyms).then(() => {
    // done
  });

  // Or if you want to also replace synonyms on replicas
  index.replaceAllSynonyms(synonyms, { forwardToReplicas: true }).then(() => {
    // done
  });
  ```

  ```kotlin Kotlin theme={"system"}
  // Fetch your synonyms
  val synonyms = listOf<Synonym>()

  index.replaceAllSynonyms(synonyms, forwardToReplicas = true)
  ```

  ```php PHP theme={"system"}
  $client = Algolia\AlgoliaSearch\SearchClient::create(
    'YourApplicationID',
    'YourWriteAPIKey'
  );

  $synonyms = /* Fetch your synonyms */;

  $index = $client->initIndex('INDEX_NAME');
  $index->replaceAllSynonyms($synonyms);

  // Or if you want to also replace synonyms on replicas
  $index->replaceAllSynonyms($synonyms, ['forwardToReplicas' => true]);
  ```

  ```python Python theme={"system"}
  client = SearchClient.create('YourApplicationID', 'YourWriteAPIKey')

  synonyms = [] # Fetch your synonyms

  index = client.init_index('INDEX_NAME')
  index.replace_all_synonyms(synonyms)

  # Or if you want to also replace synonyms on replicas
  index.replace_all_synonyms(synonyms, {'forwardToReplicas': True})
  ```

  ```ruby Ruby theme={"system"}
  client = Algolia::Search::Client.create('YourApplicationID', 'YourWriteAPIKey')

  synonyms = [] # Fetch your synonyms

  index = client.init_index('INDEX_NAME')
  index.replace_all_synonyms(synonyms)

  # Or if you want to also replace synonyms on replicas
  index.replace_all_synonyms(synonyms, { forwardToReplicas: true })
  ```

  ```swift Swift theme={"system"}
  let client = SearchClient(appID: "YourApplicationID", apiKey: "YourWriteAPIKey")
  let index = client.index(withName: "INDEX_NAME")

  let synonyms: [Synonym] = [/* Fetch your synonyms */]

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

## Parameters

<ParamField body="synonyms" type="list" required>
  A list of synonyms
</ParamField>

<ParamField body="forwardToReplicas" type="boolean" default={false}>
  Also replace synonyms on replicas
</ParamField>

<ParamField body="requestOptions" type="object">
  A mapping of request options to send along with the request.
</ParamField>
