创建或更新同义词规则
编辑创建或更新同义词规则
编辑为同义词集创建或更新同义词规则。
请求
编辑PUT _synonyms/<synonyms_set>/<synonym_rule>
前提条件
编辑需要 manage_search_synonyms
集群权限。
路径参数
编辑-
<synonyms_set>
- (必需,字符串)要更新的同义词集标识符。
-
<synonym_rule>
- (必需,字符串)要创建或更新的同义词规则标识符。
示例
编辑以下示例更新名为 test-1
的现有同义词规则,该规则用于同义词集 my-synonyms-set
resp = client.synonyms.put_synonym_rule( set_id="my-synonyms-set", rule_id="test-1", synonyms="hello, hi, howdy", ) print(resp)
response = client.synonyms.put_synonym_rule( set_id: 'my-synonyms-set', rule_id: 'test-1', body: { synonyms: 'hello, hi, howdy' } ) puts response
const response = await client.synonyms.putSynonymRule({ set_id: "my-synonyms-set", rule_id: "test-1", synonyms: "hello, hi, howdy", }); console.log(response);
PUT _synonyms/my-synonyms-set/test-1 { "synonyms": "hello, hi, howdy" }
{ "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" ] } ] } }
所有使用此同义词集的分析器都将 自动重新加载 以反映新规则。
如果包含的任何同义词规则无效,API 将返回错误。
resp = client.synonyms.put_synonym_rule( set_id="my-synonyms-set", rule_id="test-1", synonyms="hello => hi => howdy", ) print(resp)
const response = await client.synonyms.putSynonymRule({ set_id: "my-synonyms-set", rule_id: "test-1", synonyms: "hello => hi => howdy", }); console.log(response);
PUT _synonyms/my-synonyms-set/test-1 { "synonyms": "hello => hi => howdy" }
{ "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 }