---
type: api
title: Create or update a synonym set
description: Synonym sets are limited to a maximum of 100,000 synonym rules per set by default.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-synonyms-put-synonym
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-synonyms-put-synonym
products:
  - Elasticsearch
---

# Create or update a synonym set

Availability: Generally available since 8.10

## Paths

- `PUT` `/_synonyms/{id}`

#### Path parameters

- `id` (string) — required
  The ID of the synonyms set to be created or updated.

## Description

Synonym sets are limited to a maximum of 100,000 synonym rules per set by default.
This limit is configurable using the `synonyms.max_synonym_rules` cluster setting.

When an existing synonyms set is updated, the search analyzers that use the synonyms set are reloaded automatically for all indices.
This is equivalent to invoking the reload search analyzers API for all indices that use the synonyms set.

For practical examples of how to create or update a synonyms set, refer to the External documentation.

[About synonym API examples](https://www.elastic.co/docs/solutions/search/full-text/create-update-synonyms-api-example)

## Required authorization

- Cluster privileges: `manage_search_synonyms`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Query string parameters

- `refresh` (boolean · default: true) — optional
  If `true`, the request will refresh the analyzers with the new synonyms set and wait for the new synonyms to be available before returning.
If `false`, analyzers will not be reloaded with the new synonym set
- `append` (boolean · default: false) — optional
  If `true`, the provided synonym rules are appended to the existing set, with matching IDs overwriting existing rules.
If `false`, the entire synonyms set is replaced with the new synonym rules definitions.

## Request body

`application/json`

- `synonyms_set` (union oneOf) — required
  The synonym rules definitions for the synonyms set.
  `object` or `object[]`
  - `id` (string) — optional
    The identifier for the synonym rule.
If you do not specify a synonym rule ID when you create a rule, an identifier is created automatically by Elasticsearch.
  - `synonyms` (string) — required
    The synonyms that conform the synonym rule in Solr format.

## Response

`application/json`

- `result` (enum)
  The update operation result.
  Values: `created`, `updated`, `deleted`, `not_found`, `noop`
- `reload_analyzers_details` (object)
  Updating a synonyms set can reload the associated analyzers in case refresh is set to true.
This information is the analyzers reloading result.
  - `reload_details` (object[])
    - `index` (string)
    - `reloaded_analyzers` (string[])
    - `reloaded_node_ids` (string[])
  - `_shards` (object)
    - `failed` (number)
      The number of shards the operation or search attempted to run on but failed.
    - `successful` (number)
      The number of shards the operation or search succeeded on.
    - `total` (number)
      The number of shards the operation or search will run on overall.
    - `failures` (object[])
      - `index` (string)
      - `node` (string)
      - `reason` (object)
        - `type` (string)
          The type of error
        - `reason` (union string) — nullable
          A human-readable explanation of the error, in English.
          One of: `string`
        - `stack_trace` (string)
          The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
        - `caused_by` (object) — recursive
          Same fields as `reason` in `failures`
        - `root_cause` (object[]) — recursive
          Same fields as `reason` in `failures`
        - `suppressed` (object[]) — recursive
          Same fields as `reason` in `failures`
      - `shard` (number)
      - `status` (string)
      - `primary` (boolean)
    - `skipped` (number)
## Code examples

#### Console

```console
PUT _synonyms/my-synonyms-set

{
  "synonyms_set": {
  "synonyms" : "hello, hi, howdy"
  }
}
```

#### JavaScript

```javascript
const response = await client.synonyms.putSynonym({
  id: "my-synonyms-set",
  synonyms_set: {
    synonyms: "hello, hi, howdy",
  },
});
```

#### Python

```python
resp = client.synonyms.put_synonym(
    id="my-synonyms-set",
    synonyms_set={
        "synonyms": "hello, hi, howdy"
    },
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_synonyms/my-synonyms-set" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "synonyms_set": {
      "synonyms": "hello, hi, howdy"
    }
  }'
```

#### Java

```java
client.synonyms().putSynonym(p -> p
    .id("my-synonyms-set")
    .synonymsSet(s -> s
        .synonyms("hello, hi, howdy")
    )
);
```

#### C#

```c#
var response = await client.Synonyms
    .PutSynonymAsync(id: "my-synonyms-set", d1 => d1
        .SynonymsSet(d2 => d2
            .Synonyms("hello, hi, howdy")
        )
    );
```

#### PHP

```php
$resp = $client->synonyms()->putSynonym([
    "id" => "my-synonyms-set",
    "body" => [
        "synonyms_set" => [
            "synonyms" => "hello, hi, howdy",
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.synonyms.put_synonym(
  id: "my-synonyms-set",
  body: {
    "synonyms_set": {
      "synonyms": "hello, hi, howdy"
    }
  }
)
```

