add-alias.asciidoc 3.4 KB

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