[[put-synonym-rule]] === Create or update synonym rule beta::[] ++++ Create or update synonym rule ++++ Creates or updates a synonym rule for a synonym set. [[put-synonym-rule-request]] ==== {api-request-title} `PUT _synonyms//` [[put-synonym-rule-prereqs]] ==== {api-prereq-title} Requires the `manage_search_synonyms` cluster privilege. [[put-synonym-rule-path-params]] ==== {api-path-parms-title} ``:: (Required, string) Synonyms set identifier to update. ``:: (Required, string) Synonym rule identifier to create or update. [[put-synonym-rule-request-body]] ==== {api-request-body-title} `synonyms`:: (Required, string) The synonym rule definition. This needs to be in <<_solr_synonyms>> format. Some examples are: * "i-pod, i pod => ipod", * "universe, cosmos" [[put-synonym-rule-example]] ==== {api-examples-title} The following example updates an existing synonym rule called `test-1` for the synonyms set `my-synonyms-set`: //// [source,console] ---- PUT _synonyms/my-synonyms-set { "synonyms_set": [ { "id": "test-1", "synonyms": "hello, hi" }, { "synonyms": "bye, goodbye" }, { "id": "test-2", "synonyms": "test => check" } ] } PUT /test-index { "settings": { "analysis": { "filter": { "synonyms_filter": { "type": "synonym_graph", "synonyms_set": "my-synonyms-set", "updateable": true } }, "analyzer": { "my_index_analyzer": { "type": "custom", "tokenizer": "standard", "filter": ["lowercase"] }, "my_search_analyzer": { "type": "custom", "tokenizer": "standard", "filter": ["lowercase", "synonyms_filter"] } } } }, "mappings": { "properties": { "title": { "type": "text", "analyzer": "my_index_analyzer", "search_analyzer": "my_search_analyzer" } } } } ---- // TESTSETUP //// [source,console] ---- PUT _synonyms/my-synonyms-set/test-1 { "synonyms": "hello, hi, howdy" } ---- [source,console-result] ---- { "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" ] } ] } } ---- // TESTRESPONSE[s/1wYFZzq8Sxeu_Jvt9mlbkg/$body.reload_analyzers_details.reload_details.0.reloaded_node_ids.0/] All analyzers using this synonyms set will be <> to reflect the new rule. If any of the synonym rules included is invalid, the API will return an error. [source,console] ---- PUT _synonyms/my-synonyms-set/test-1 { "synonyms": "hello => hi => howdy" } ---- // TEST[catch:bad_request] [source,console-result] ---- { "error": { "root_cause": [ { "type": "action_request_validation_exception", "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];", "stack_trace": ... } ], "type": "action_request_validation_exception", "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];", "stack_trace": ... }, "status": 400 } ---- // TESTRESPONSE[s/"stack_trace": \.\.\./"stack_trace": $body.$_path/]