add-alias.asciidoc 3.5 KB

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