Create or update a synonym rule Generally available; Added in 8.10.0

PUT /_synonyms/{set_id}/{rule_id}

Create or update a synonym rule in a synonym set.

If any of the synonym rules included is invalid, the API returns an error.

When you update a synonym rule, all analyzers using the synonyms set will be reloaded automatically to reflect the new rule.

Required authorization

  • Cluster privileges: manage_search_synonyms

Path parameters

  • set_id string Required

    The ID of the synonym set.

  • rule_id string Required

    The ID of the synonym rule to be updated or created.

Query parameters

  • refresh boolean

    If true, the request will refresh the analyzers with the new synonym rule and wait for the new synonyms to be available before returning. If false, analyzers will not be reloaded with the new synonym rule

application/json

Body Required

Responses

  • 200 application/json
    Hide response attributes Show response attributes object
    • result string Required

      Values are created, updated, deleted, not_found, or noop.

    • Hide reload_analyzers_details attributes Show reload_analyzers_details attributes object
      • reload_details array[object] Required
        Hide reload_details attributes Show reload_details attributes object
      • _shards object Required
        Hide _shards attributes Show _shards attributes object
        • failed number Required
        • successful number Required
        • total number Required
        • failures array[object]
          Hide failures attributes Show failures attributes object
          • index string
          • node string
          • reason object Required

            Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

            Hide reason attributes Show reason attributes object
            • type string Required

              The type of error

            • The server stack trace. Present only if the error_trace=true parameter was sent with the request.

            • Cause and details about a request failure. This class defines the properties common to all error types. Additional details are also provided, that depend on the error type.

            • root_cause array[object]
            • suppressed array[object]
          • shard number Required
          • status string
        • skipped number
PUT /_synonyms/{set_id}/{rule_id}
PUT _synonyms/my-synonyms-set/test-1
{
  "synonyms": "hello, hi, howdy"
}
resp = client.synonyms.put_synonym_rule(
    set_id="my-synonyms-set",
    rule_id="test-1",
    synonyms="hello, hi, howdy",
)
const response = await client.synonyms.putSynonymRule({
  set_id: "my-synonyms-set",
  rule_id: "test-1",
  synonyms: "hello, hi, howdy",
});
response = client.synonyms.put_synonym_rule(
  set_id: "my-synonyms-set",
  rule_id: "test-1",
  body: {
    "synonyms": "hello, hi, howdy"
  }
)
$resp = $client->synonyms()->putSynonymRule([
    "set_id" => "my-synonyms-set",
    "rule_id" => "test-1",
    "body" => [
        "synonyms" => "hello, hi, howdy",
    ],
]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"synonyms":"hello, hi, howdy"}' "$ELASTICSEARCH_URL/_synonyms/my-synonyms-set/test-1"
Request example
{
  "synonyms": "hello, hi, howdy"
}
Response examples (200)
A successful response from `PUT _synonyms/my-synonyms-set/test-1`.
{
  "result": "updated",
  "reload_analyzers_details": {
    "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
    },
    "reload_details": [
      {
        "index": "test-index",
        "reloaded_analyzers": [
          "my_search_analyzer"
        ],
        "reloaded_node_ids": [
          "1wYFZzq8Sxeu_Jvt9mlbkg"
        ]
      }
    ]
  }
}