update-settings.asciidoc 5.1 KB

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