reload-analyzers.asciidoc 5.0 KB

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