update-settings.asciidoc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. [[indices-update-settings]]
  2. === Update index settings API
  3. ++++
  4. <titleabbrev>Update index settings</titleabbrev>
  5. ++++
  6. Changes a <<index-modules-settings,dynamic index setting>> in real time.
  7. For data streams, index setting changes are applied to all backing indices by
  8. default.
  9. [source,console]
  10. --------------------------------------------------
  11. PUT /my-index-000001/_settings
  12. {
  13. "index" : {
  14. "number_of_replicas" : 2
  15. }
  16. }
  17. --------------------------------------------------
  18. // TEST[setup:my_index]
  19. [[update-index-settings-api-request]]
  20. ==== {api-request-title}
  21. `PUT /<target>/_settings`
  22. [[update-index-settings-api-prereqs]]
  23. ==== {api-prereq-title}
  24. * If the {es} {security-features} are enabled, you must have the `manage`
  25. <<privileges-list-indices,index privilege>> for the target data stream, index,
  26. or index alias.
  27. [[update-index-settings-api-path-params]]
  28. ==== {api-path-parms-title}
  29. `<target>`::
  30. (Optional, string)
  31. Comma-separated list of data streams, indices, and index aliases used to limit
  32. the request. Wildcard expressions (`*`) are supported.
  33. +
  34. To target all data streams and indices in a cluster, omit this parameter or use
  35. `_all` or `*`.
  36. [[update-index-settings-api-query-params]]
  37. ==== {api-query-parms-title}
  38. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  39. +
  40. Defaults to `false`.
  41. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  42. +
  43. Defaults to `open`.
  44. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=flat-settings]
  45. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  46. `preserve_existing`::
  47. (Optional, Boolean) If `true`, existing index settings remain unchanged.
  48. Defaults to `false`.
  49. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  50. [[update-index-settings-api-request-body]]
  51. ==== {api-request-body-title}
  52. `settings`::
  53. (Optional, <<index-modules-settings,index setting object>>) Configuration
  54. options for the index. See <<index-modules-settings>>.
  55. [[update-index-settings-api-example]]
  56. ==== {api-examples-title}
  57. [[reset-index-setting]]
  58. ===== Reset an index setting
  59. To revert a setting to the default value, use `null`. For example:
  60. [source,console]
  61. --------------------------------------------------
  62. PUT /my-index-000001/_settings
  63. {
  64. "index" : {
  65. "refresh_interval" : null
  66. }
  67. }
  68. --------------------------------------------------
  69. // TEST[setup:my_index]
  70. The list of per-index settings which can be updated dynamically on live
  71. indices can be found in <<index-modules>>.
  72. To preserve existing settings from being updated, the `preserve_existing`
  73. request parameter can be set to `true`.
  74. [[bulk]]
  75. ===== Bulk indexing usage
  76. For example, the update settings API can be used to dynamically change
  77. the index from being more performant for bulk indexing, and then move it
  78. to more real time indexing state. Before the bulk indexing is started,
  79. use:
  80. [source,console]
  81. --------------------------------------------------
  82. PUT /my-index-000001/_settings
  83. {
  84. "index" : {
  85. "refresh_interval" : "-1"
  86. }
  87. }
  88. --------------------------------------------------
  89. // TEST[setup:my_index]
  90. (Another optimization option is to start the index without any replicas,
  91. and only later adding them, but that really depends on the use case).
  92. Then, once bulk indexing is done, the settings can be updated (back to
  93. the defaults for example):
  94. [source,console]
  95. --------------------------------------------------
  96. PUT /my-index-000001/_settings
  97. {
  98. "index" : {
  99. "refresh_interval" : "1s"
  100. }
  101. }
  102. --------------------------------------------------
  103. // TEST[continued]
  104. And, a force merge should be called:
  105. [source,console]
  106. --------------------------------------------------
  107. POST /my-index-000001/_forcemerge?max_num_segments=5
  108. --------------------------------------------------
  109. // TEST[continued]
  110. [[update-settings-analysis]]
  111. ===== Update index analysis
  112. You can only define new analyzers on closed indices.
  113. To add an analyzer,
  114. you must close the index,
  115. define the analyzer,
  116. and reopen the index.
  117. [NOTE]
  118. ====
  119. You cannot close the write index of a data stream.
  120. To update the analyzer for a data stream's write index and future backing
  121. indices, update the analyzer in the <<create-index-template,index
  122. template used by the stream>>. Then <<manually-roll-over-a-data-stream,roll over
  123. the data stream>> to apply the new analyzer to the stream’s write index and
  124. future backing indices. This affects searches and any new data added to the
  125. stream after the rollover. However, it does not affect the data stream's backing
  126. indices or their existing data.
  127. To change the analyzer for existing backing indices, you must create a
  128. new data stream and reindex your data into it. See
  129. <<data-streams-use-reindex-to-change-mappings-settings>>.
  130. ====
  131. For example,
  132. the following commands add the `content` analyzer to the `my-index-000001` index:
  133. [source,console]
  134. --------------------------------------------------
  135. POST /my-index-000001/_close
  136. PUT /my-index-000001/_settings
  137. {
  138. "analysis" : {
  139. "analyzer":{
  140. "content":{
  141. "type":"custom",
  142. "tokenizer":"whitespace"
  143. }
  144. }
  145. }
  146. }
  147. POST /my-index-000001/_open
  148. --------------------------------------------------
  149. // TEST[setup:my_index]