put-synonym-rule.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. [[put-synonym-rule]]
  2. === Create or update synonym rule
  3. beta::[]
  4. ++++
  5. <titleabbrev>Create or update synonym rule</titleabbrev>
  6. ++++
  7. Creates or updates a synonym rule for a synonym set.
  8. [[put-synonym-rule-request]]
  9. ==== {api-request-title}
  10. `PUT _synonyms/<synonyms_set>/<synonym_rule>`
  11. [[put-synonym-rule-prereqs]]
  12. ==== {api-prereq-title}
  13. Requires the `manage_search_synonyms` cluster privilege.
  14. [[put-synonym-rule-path-params]]
  15. ==== {api-path-parms-title}
  16. `<synonyms_set>`::
  17. (Required, string)
  18. Synonyms set identifier to update.
  19. `<synonym_rule>`::
  20. (Required, string)
  21. Synonym rule identifier to create or update.
  22. [[put-synonym-rule-request-body]]
  23. ==== {api-request-body-title}
  24. `synonyms`::
  25. (Required, string)
  26. The synonym rule definition.
  27. This needs to be in <<_solr_synonyms>> format. Some examples are:
  28. * "i-pod, i pod => ipod",
  29. * "universe, cosmos"
  30. [[put-synonym-rule-example]]
  31. ==== {api-examples-title}
  32. The following example updates an existing synonym rule called `test-1` for the synonyms set `my-synonyms-set`:
  33. ////
  34. [source,console]
  35. ----
  36. PUT _synonyms/my-synonyms-set
  37. {
  38. "synonyms_set": [
  39. {
  40. "id": "test-1",
  41. "synonyms": "hello, hi"
  42. },
  43. {
  44. "synonyms": "bye, goodbye"
  45. },
  46. {
  47. "id": "test-2",
  48. "synonyms": "test => check"
  49. }
  50. ]
  51. }
  52. PUT /test-index
  53. {
  54. "settings": {
  55. "analysis": {
  56. "filter": {
  57. "synonyms_filter": {
  58. "type": "synonym_graph",
  59. "synonyms_set": "my-synonyms-set",
  60. "updateable": true
  61. }
  62. },
  63. "analyzer": {
  64. "my_index_analyzer": {
  65. "type": "custom",
  66. "tokenizer": "standard",
  67. "filter": ["lowercase"]
  68. },
  69. "my_search_analyzer": {
  70. "type": "custom",
  71. "tokenizer": "standard",
  72. "filter": ["lowercase", "synonyms_filter"]
  73. }
  74. }
  75. }
  76. },
  77. "mappings": {
  78. "properties": {
  79. "title": {
  80. "type": "text",
  81. "analyzer": "my_index_analyzer",
  82. "search_analyzer": "my_search_analyzer"
  83. }
  84. }
  85. }
  86. }
  87. ----
  88. // TESTSETUP
  89. ////
  90. [source,console]
  91. ----
  92. PUT _synonyms/my-synonyms-set/test-1
  93. {
  94. "synonyms": "hello, hi, howdy"
  95. }
  96. ----
  97. [source,console-result]
  98. ----
  99. {
  100. "result": "updated",
  101. "reload_analyzers_details": {
  102. "_shards": {
  103. "total": 2,
  104. "successful": 1,
  105. "failed": 0
  106. },
  107. "reload_details": [
  108. {
  109. "index": "test-index",
  110. "reloaded_analyzers": [
  111. "my_search_analyzer"
  112. ],
  113. "reloaded_node_ids": [
  114. "1wYFZzq8Sxeu_Jvt9mlbkg"
  115. ]
  116. }
  117. ]
  118. }
  119. }
  120. ----
  121. // TESTRESPONSE[s/1wYFZzq8Sxeu_Jvt9mlbkg/$body.reload_analyzers_details.reload_details.0.reloaded_node_ids.0/]
  122. All analyzers using this synonyms set will be <<synonyms-set-analyzer-reloading,reloaded automatically>> to reflect the new rule.
  123. If any of the synonym rules included is invalid, the API will return an error.
  124. [source,console]
  125. ----
  126. PUT _synonyms/my-synonyms-set/test-1
  127. {
  128. "synonyms": "hello => hi => howdy"
  129. }
  130. ----
  131. // TEST[catch:bad_request]
  132. [source,console-result]
  133. ----
  134. {
  135. "error": {
  136. "root_cause": [
  137. {
  138. "type": "action_request_validation_exception",
  139. "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
  140. "stack_trace": ...
  141. }
  142. ],
  143. "type": "action_request_validation_exception",
  144. "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
  145. "stack_trace": ...
  146. },
  147. "status": 400
  148. }
  149. ----
  150. // TESTRESPONSE[s/"stack_trace": \.\.\./"stack_trace": $body.$_path/]