---
type: api
title: Get a synonym rule
description: Get a synonym rule from a synonym set.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-synonyms-get-synonym-rule
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-synonyms-get-synonym-rule
products:
  - Elasticsearch
---

# Get a synonym rule

Availability: Generally available since 8.10

## Paths

- `GET` `/_synonyms/{set_id}/{rule_id}`

#### Path parameters

- `set_id` (string) — required
  The ID of the synonym set to retrieve the synonym rule from.
- `rule_id` (string) — required
  The ID of the synonym rule to retrieve.

## Description

Get a synonym rule from a synonym set.

## 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)

## Response

`application/json`

- `id` (string)
  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)
  The synonyms that conform the synonym rule in Solr format.
## Code examples

#### Console

```console
GET _synonyms/my-synonyms-set/test-1
```

#### JavaScript

```javascript
const response = await client.synonyms.getSynonymRule({
  set_id: "my-synonyms-set",
  rule_id: "test-1",
});
```

#### Python

```python
resp = client.synonyms.get_synonym_rule(
    set_id="my-synonyms-set",
    rule_id="test-1",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_synonyms/my-synonyms-set/test-1" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.synonyms().getSynonymRule(g -> g
    .ruleId("test-1")
    .setId("my-synonyms-set")
);
```

#### C#

```c#
var response = await client.Synonyms.GetSynonymRuleAsync(setId: "my-synonyms-set", ruleId: "test-1");
```

#### PHP

```php
$resp = $client->synonyms()->getSynonymRule([
    "set_id" => "my-synonyms-set",
    "rule_id" => "test-1",
]);
```

#### Ruby

```ruby
response = client.synonyms.get_synonym_rule(
  set_id: "my-synonyms-set",
  rule_id: "test-1"
)
```

## Response examples

#### Synonym rule get response example1

A successful response from `GET _synonyms/my-synonyms-set/test-1`.

```json
{
  "id": "test-1",
  "synonyms": "hello, hi"
}
```

