add-alias.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. [[indices-add-alias]]
  2. === Create or update index alias API
  3. ++++
  4. <titleabbrev>Create or update index alias</titleabbrev>
  5. ++++
  6. Creates or updates an index alias.
  7. include::{es-repo-dir}/glossary.asciidoc[tag=index-alias-desc]
  8. [source,console]
  9. ----
  10. PUT /my-index-000001/_alias/alias1
  11. ----
  12. // TEST[setup:my_index]
  13. [[add-alias-api-request]]
  14. ==== {api-request-title}
  15. `PUT /<index>/_alias/<alias>`
  16. `POST /<index>/_alias/<alias>`
  17. `PUT /<index>/_aliases/<alias>`
  18. `POST /<index>/_aliases/<alias>`
  19. [[add-alias-api-prereqs]]
  20. ==== {api-prereq-title}
  21. * If the {es} {security-features} are enabled, you must have the `manage`
  22. <<privileges-list-indices,index privilege>> for both the index and index alias.
  23. [[add-alias-api-path-params]]
  24. ==== {api-path-parms-title}
  25. `<index>`::
  26. (Required, string)
  27. Comma-separated list or wildcard expression of index names
  28. to add to the alias.
  29. +
  30. To add all indices in the cluster to the alias,
  31. use a value of `_all`.
  32. +
  33. NOTE: You cannot add <<data-streams,data streams>> to an index alias.
  34. `<alias>`::
  35. (Required, string)
  36. Name of the index alias to create or update. Supports
  37. <<date-math-index-names,date math>>.
  38. [[add-alias-api-query-params]]
  39. ==== {api-query-parms-title}
  40. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  41. [[add-alias-api-request-body]]
  42. ==== {api-request-body-title}
  43. `filter`::
  44. (Required, query object)
  45. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-alias-filter]
  46. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-routing]
  47. [[add-alias-api-example]]
  48. ==== {api-examples-title}
  49. [[alias-date-math-support]]
  50. ===== Date math support
  51. Index alias names support <<date-math-index-names,date math>>.
  52. [source,console]
  53. ----
  54. # POST /logs/_alias/<logs_{now/M}>
  55. POST /logs/_alias/%3Clogs_%7Bnow%2FM%7D%3E
  56. ----
  57. // TEST[s/^/PUT logs\n/]
  58. [[alias-adding]]
  59. ===== Add a time-based alias
  60. The following request creates an alias, `2030`,
  61. for the `logs_20302801` index.
  62. [source,console]
  63. --------------------------------------------------
  64. PUT /logs_20302801/_alias/2030
  65. --------------------------------------------------
  66. // TEST[s/^/PUT logs_20302801\n/]
  67. [[add-alias-api-user-ex]]
  68. ===== Add a user-based alias
  69. First, create an index, `users`,
  70. with a mapping for the `user_id` field:
  71. [source,console]
  72. --------------------------------------------------
  73. PUT /users
  74. {
  75. "mappings" : {
  76. "properties" : {
  77. "user_id" : {"type" : "integer"}
  78. }
  79. }
  80. }
  81. --------------------------------------------------
  82. Then add the index alias for a specific user, `user_12`:
  83. [source,console]
  84. --------------------------------------------------
  85. PUT /users/_alias/user_12
  86. {
  87. "routing" : "12",
  88. "filter" : {
  89. "term" : {
  90. "user_id" : 12
  91. }
  92. }
  93. }
  94. --------------------------------------------------
  95. // TEST[continued]
  96. [[alias-index-creation]]
  97. ===== Add an alias during index creation
  98. You can use the <<create-index-aliases,create index API>>
  99. to add an index alias during index creation.
  100. [source,console]
  101. --------------------------------------------------
  102. PUT /logs_20302801
  103. {
  104. "mappings": {
  105. "properties": {
  106. "year": { "type": "integer" }
  107. }
  108. },
  109. "aliases": {
  110. "current_day": {},
  111. "2030": {
  112. "filter": {
  113. "term": { "year": 2030 }
  114. }
  115. }
  116. }
  117. }
  118. --------------------------------------------------
  119. The create index API also supports <<date-math-index-names,date math>> in index
  120. alias names.
  121. [source,console]
  122. ----
  123. PUT /logs
  124. {
  125. "aliases": {
  126. "<logs_{now/M}>": {}
  127. }
  128. }
  129. ----