reload-analyzers.asciidoc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[indices-reload-analyzers]]
  4. == Reload search analyzers API
  5. ++++
  6. <titleabbrev>Reload search analyzers</titleabbrev>
  7. ++++
  8. Reloads an index's <<search-analyzer,search analyzers>> and their resources.
  9. For data streams, the API reloads search analyzers and resources for the
  10. stream's backing indices.
  11. [source,console]
  12. --------------------------------------------------
  13. POST /my-index-000001/_reload_search_analyzers
  14. POST /my-index-000001/_cache/clear?request=true
  15. --------------------------------------------------
  16. // TEST[setup:my_index]
  17. IMPORTANT: After reloading the search analyzers you should clear the request
  18. cache to make sure it doesn't contain responses derived from the
  19. previous versions of the analyzer.
  20. // the need for this is tracked in https://github.com/elastic/elasticsearch/issues/66722
  21. [discrete]
  22. [[indices-reload-analyzers-api-request]]
  23. === {api-request-title}
  24. `POST /<target>/_reload_search_analyzers`
  25. `GET /<target>/_reload_search_analyzers`
  26. [discrete]
  27. [[indices-reload-analyzers-api-desc]]
  28. === {api-description-title}
  29. You can use the reload search analyzers API
  30. to pick up changes to synonym files
  31. used in the <<analysis-synonym-graph-tokenfilter,`synonym_graph`>>
  32. or <<analysis-synonym-tokenfilter,`synonym`>> token filter
  33. of a <<search-analyzer,search analyzer>>.
  34. To be eligible,
  35. the token filter must have an `updateable` flag of `true`
  36. and only be used in search analyzers.
  37. [NOTE]
  38. ====
  39. This API does not perform a reload
  40. for each shard of an index.
  41. Instead,
  42. it performs a reload for each node
  43. containing index shards.
  44. As a result,
  45. the total shard count returned by the API
  46. can differ from the number of index shards.
  47. Because reloading affects every node with an index shard,
  48. its important to update the synonym file
  49. on every data node in the cluster,
  50. including nodes that don't contain a shard replica,
  51. before using this API.
  52. This ensures the synonym file is updated
  53. everywhere in the cluster
  54. in case shards are relocated
  55. in the future.
  56. ====
  57. [discrete]
  58. [[indices-reload-analyzers-api-path-params]]
  59. === {api-path-parms-title}
  60. `<target>`::
  61. (Required, string)
  62. Comma-separated list of data streams, indices, and index aliases used to limit
  63. the request. Wildcard expressions (`*`) are supported.
  64. +
  65. To target all data streams and indices in a cluster, use `_all` or `*`.
  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/]