put-synonyms-set.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. [[put-synonyms-set]]
  2. === Create or update synonyms set
  3. beta::[]
  4. ++++
  5. <titleabbrev>Create or update synonyms set</titleabbrev>
  6. ++++
  7. Creates or updates a synonyms set.
  8. [[put-synonyms-set-request]]
  9. ==== {api-request-title}
  10. `PUT _synonyms/<synonyms_set>`
  11. [[put-synonyms-set-prereqs]]
  12. ==== {api-prereq-title}
  13. Requires the `manage_search_synonyms` cluster privilege.
  14. [[put-synonyms-set-path-params]]
  15. ==== {api-path-parms-title}
  16. `<synonyms_set>`::
  17. (Required, string)
  18. Synonyms set identifier to create.
  19. This identifier will be used by other <<synonyms-apis>> to manage the synonyms set.
  20. [[put-synonyms-set-api-request-body]]
  21. ==== {api-request-body-title}
  22. `synonyms_set`::
  23. (Required, array of synonym rules objects)
  24. The synonym rules definitions for the synonyms set.
  25. .Properties of `synonyms_set` objects
  26. [%collapsible%open]
  27. =====
  28. `id`::
  29. (Optional, string)
  30. The identifier associated to the synonym rule, that can be used to manage individual synonym rules via <<synonym-rules-apis,synonym rules APIs>>.
  31. In case a synonym rule id is not specified, an identifier will be created automatically by {es}.
  32. `synonyms`::
  33. (Required, string)
  34. The synonym rule. This needs to be in <<_solr_synonyms>> format.
  35. Some examples are:
  36. * "i-pod, i pod => ipod",
  37. * "universe, cosmos"
  38. =====
  39. [[put-synonyms-set-example]]
  40. ==== {api-examples-title}
  41. The following example creates a new synonyms set called `my-synonyms-set`:
  42. [source,console]
  43. ----
  44. PUT _synonyms/my-synonyms-set
  45. {
  46. "synonyms_set": [
  47. {
  48. "id": "test-1",
  49. "synonyms": "hello, hi"
  50. },
  51. {
  52. "synonyms": "bye, goodbye"
  53. },
  54. {
  55. "id": "test-2",
  56. "synonyms": "test => check"
  57. }
  58. ]
  59. }
  60. ----
  61. If any of the synonym rules included is not valid, the API will return an error.
  62. [source,console]
  63. ----
  64. PUT _synonyms/my-synonyms-set
  65. {
  66. "synonyms_set": [
  67. {
  68. "synonyms": "hello => hi => howdy"
  69. }
  70. ]
  71. }
  72. ----
  73. // TEST[catch:bad_request]
  74. [source,console-result]
  75. ----
  76. {
  77. "error": {
  78. "root_cause": [
  79. {
  80. "type": "action_request_validation_exception",
  81. "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
  82. "stack_trace": ...
  83. }
  84. ],
  85. "type": "action_request_validation_exception",
  86. "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
  87. "stack_trace": ...
  88. },
  89. "status": 400
  90. }
  91. ----
  92. // TESTRESPONSE[s/"stack_trace": \.\.\./"stack_trace": $body.$_path/]
  93. [[synonyms-set-analyzer-reloading]]
  94. ==== Analyzer reloading
  95. When an existing synonyms set is updated, the <<search-analyzer, search analyzers>> that use the synonyms set are reloaded automatically for all indices.
  96. This would be equivalent to invoking <<indices-reload-analyzers>> for all indices that use the synonyms set.
  97. For example, creating an index with a synonyms set and updating it:
  98. [source,console]
  99. ----
  100. PUT _synonyms/my-synonyms-set
  101. {
  102. "synonyms_set": [
  103. {
  104. "id": "test-1",
  105. "synonyms": "hello, hi"
  106. }
  107. ]
  108. }
  109. PUT /test-index
  110. {
  111. "settings": {
  112. "analysis": {
  113. "filter": {
  114. "synonyms_filter": {
  115. "type": "synonym_graph",
  116. "synonyms_set": "my-synonyms-set",
  117. "updateable": true
  118. }
  119. },
  120. "analyzer": {
  121. "my_index_analyzer": {
  122. "type": "custom",
  123. "tokenizer": "standard",
  124. "filter": ["lowercase"]
  125. },
  126. "my_search_analyzer": {
  127. "type": "custom",
  128. "tokenizer": "standard",
  129. "filter": ["lowercase", "synonyms_filter"]
  130. }
  131. }
  132. }
  133. },
  134. "mappings": {
  135. "properties": {
  136. "title": {
  137. "type": "text",
  138. "analyzer": "my_index_analyzer",
  139. "search_analyzer": "my_search_analyzer"
  140. }
  141. }
  142. }
  143. }
  144. PUT _synonyms/my-synonyms-set
  145. {
  146. "synonyms_set": [
  147. {
  148. "id": "test-1",
  149. "synonyms": "hello, hi, howdy"
  150. }
  151. ]
  152. }
  153. ----
  154. The reloading result is included as part of the response:
  155. [source,console-result]
  156. ----
  157. {
  158. "result": "updated",
  159. "reload_analyzers_details": {
  160. "_shards": {
  161. "total": 2,
  162. "successful": 1,
  163. "failed": 0
  164. },
  165. "reload_details": [
  166. {
  167. "index": "test-index",
  168. "reloaded_analyzers": [
  169. "my_search_analyzer"
  170. ],
  171. "reloaded_node_ids": [
  172. "1wYFZzq8Sxeu_Jvt9mlbkg"
  173. ]
  174. }
  175. ]
  176. }
  177. }
  178. ----
  179. // TESTRESPONSE[s/1wYFZzq8Sxeu_Jvt9mlbkg/$body.reload_analyzers_details.reload_details.0.reloaded_node_ids.0/]