创建或更新同义词规则编辑

为同义词集创建或更新同义词规则。

请求编辑

PUT _synonyms/<synonyms_set>/<synonym_rule>

先决条件编辑

需要 manage_search_synonyms 集群权限。

路径参数编辑

<synonyms_set>
(必填,字符串)要更新的同义词集标识符。
<synonym_rule>
(必填,字符串)要创建或更新的同义词规则标识符。

请求正文编辑

synonyms

(必填,字符串)同义词规则定义。这需要采用 Solr 格式。以下是一些示例:

  • "i-pod, i pod ⇒ ipod",
  • "universe, cosmos"

示例编辑

以下示例更新了同义词集 my-synonyms-set 中名为 test-1 的现有同义词规则。

response = client.synonyms.put_synonym_rule(
  set_id: 'my-synonyms-set',
  rule_id: 'test-1',
  body: {
    synonyms: 'hello, hi, howdy'
  }
)
puts 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 将返回错误。

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
}