update-settings.asciidoc 4.9 KB

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