reload-analyzers.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. [role="xpack"]
  2. [[indices-reload-analyzers]]
  3. == Reload search analyzers API
  4. Reloads an index's <<search-analyzer,search analyzers>> and their resources.
  5. For data streams, the API reloads search analyzers and resources for the
  6. stream's backing indices.
  7. [source,console]
  8. --------------------------------------------------
  9. POST /my-index-000001/_reload_search_analyzers
  10. POST /my-index-000001/_cache/clear?request=true
  11. --------------------------------------------------
  12. // TEST[setup:my_index]
  13. IMPORTANT: After reloading the search analyzers you should clear the request
  14. cache to make sure it doesn't contain responses derived from the
  15. previous versions of the analyzer.
  16. // the need for this is tracked in https://github.com/elastic/elasticsearch/issues/66722
  17. [discrete]
  18. [[indices-reload-analyzers-api-request]]
  19. === {api-request-title}
  20. `POST /<target>/_reload_search_analyzers`
  21. `GET /<target>/_reload_search_analyzers`
  22. [discrete]
  23. [[indices-reload-analyzers-api-prereqs]]
  24. === {api-prereq-title}
  25. * If the {es} {security-features} are enabled, you must have the `manage`
  26. <<privileges-list-indices,index privilege>> for the target data stream, index,
  27. or alias.
  28. [discrete]
  29. [[indices-reload-analyzers-api-desc]]
  30. === {api-description-title}
  31. You can use the reload search analyzers API
  32. to pick up changes to synonym files
  33. used in the <<analysis-synonym-graph-tokenfilter,`synonym_graph`>>
  34. or <<analysis-synonym-tokenfilter,`synonym`>> token filter
  35. of a <<search-analyzer,search analyzer>>.
  36. To be eligible,
  37. the token filter must have an `updateable` flag of `true`
  38. and only be used in search analyzers.
  39. [NOTE]
  40. ====
  41. This API does not perform a reload
  42. for each shard of an index.
  43. Instead,
  44. it performs a reload for each node
  45. containing index shards.
  46. As a result,
  47. the total shard count returned by the API
  48. can differ from the number of index shards.
  49. Because reloading affects every node with an index shard,
  50. its important to update the synonym file
  51. on every data node in the cluster,
  52. including nodes that don't contain a shard replica,
  53. before using this API.
  54. This ensures the synonym file is updated
  55. everywhere in the cluster
  56. in case shards are relocated
  57. in the future.
  58. ====
  59. [discrete]
  60. [[indices-reload-analyzers-api-path-params]]
  61. === {api-path-parms-title}
  62. `<target>`::
  63. (Required, string) Comma-separated list of data streams, indices, and aliases
  64. used to limit the request. Supports wildcards (`*`). To target all data streams
  65. and indices, use `*` or `_all`.
  66. [discrete]
  67. [[indices-reload-analyzers-api-query-params]]
  68. === {api-query-parms-title}
  69. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  70. +
  71. Defaults to `true`.
  72. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  73. +
  74. Defaults to `open`.
  75. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  76. [discrete]
  77. [[indices-reload-analyzers-api-example]]
  78. === {api-examples-title}
  79. Use the <<indices-create-index, create index API>>
  80. to create an index with a search analyzer
  81. that contains an updateable synonym filter.
  82. NOTE: Using the following analyzer as an index analyzer results in an error.
  83. [source,console]
  84. --------------------------------------------------
  85. PUT /my-index-000001
  86. {
  87. "settings": {
  88. "index": {
  89. "analysis": {
  90. "analyzer": {
  91. "my_synonyms": {
  92. "tokenizer": "whitespace",
  93. "filter": [ "synonym" ]
  94. }
  95. },
  96. "filter": {
  97. "synonym": {
  98. "type": "synonym_graph",
  99. "synonyms_path": "analysis/synonym.txt", <1>
  100. "updateable": true <2>
  101. }
  102. }
  103. }
  104. }
  105. },
  106. "mappings": {
  107. "properties": {
  108. "text": {
  109. "type": "text",
  110. "analyzer": "standard",
  111. "search_analyzer": "my_synonyms" <3>
  112. }
  113. }
  114. }
  115. }
  116. --------------------------------------------------
  117. <1> Includes a synonym file.
  118. <2> Marks the token filter as updateable.
  119. <3> Marks the analyzer as a search analyzer.
  120. After updating the synonym file,
  121. use the <<indices-reload-analyzers,analyzer reload API>>
  122. to reload the search analyzer
  123. and pick up the file changes.
  124. [source,console]
  125. --------------------------------------------------
  126. POST /my-index-000001/_reload_search_analyzers
  127. --------------------------------------------------
  128. // TEST[continued]
  129. The API returns the following response.
  130. [source,console-result]
  131. --------------------------------------------------
  132. {
  133. "_shards": {
  134. "total": 2,
  135. "successful": 2,
  136. "failed": 0
  137. },
  138. "reload_details": [
  139. {
  140. "index": "my-index-000001",
  141. "reloaded_analyzers": [
  142. "my_synonyms"
  143. ],
  144. "reloaded_node_ids": [
  145. "mfdqTXn_T7SGr2Ho2KT8uw"
  146. ]
  147. }
  148. ]
  149. }
  150. --------------------------------------------------
  151. // TEST[continued]
  152. // TESTRESPONSE[s/"total": 2/"total": $body._shards.total/]
  153. // TESTRESPONSE[s/"successful": 2/"successful": $body._shards.successful/]
  154. // TESTRESPONSE[s/mfdqTXn_T7SGr2Ho2KT8uw/$body.reload_details.0.reloaded_node_ids.0/]