add-alias.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.
  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. (Required, 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=index-routing]
  46. [[add-alias-api-example]]
  47. ==== {api-examples-title}
  48. [[alias-adding]]
  49. ===== Add a time-based alias
  50. The following request creates an alias, `2030`,
  51. for the `logs_20302801` index.
  52. [source,console]
  53. --------------------------------------------------
  54. PUT /logs_20302801/_alias/2030
  55. --------------------------------------------------
  56. // TEST[s/^/PUT logs_20302801\n/]
  57. [[add-alias-api-user-ex]]
  58. ===== Add a user-based alias
  59. First, create an index, `users`,
  60. with a mapping for the `user_id` field:
  61. [source,console]
  62. --------------------------------------------------
  63. PUT /users
  64. {
  65. "mappings" : {
  66. "properties" : {
  67. "user_id" : {"type" : "integer"}
  68. }
  69. }
  70. }
  71. --------------------------------------------------
  72. Then add the index alias for a specific user, `user_12`:
  73. [source,console]
  74. --------------------------------------------------
  75. PUT /users/_alias/user_12
  76. {
  77. "routing" : "12",
  78. "filter" : {
  79. "term" : {
  80. "user_id" : 12
  81. }
  82. }
  83. }
  84. --------------------------------------------------
  85. // TEST[continued]
  86. [[alias-index-creation]]
  87. ===== Add an alias during index creation
  88. You can use the <<create-index-aliases,create index API>>
  89. to add an index alias during index creation.
  90. [source,console]
  91. --------------------------------------------------
  92. PUT /logs_20302801
  93. {
  94. "mappings": {
  95. "properties": {
  96. "year": { "type": "integer" }
  97. }
  98. },
  99. "aliases": {
  100. "current_day": {},
  101. "2030": {
  102. "filter": {
  103. "term": { "year": 2030 }
  104. }
  105. }
  106. }
  107. }
  108. --------------------------------------------------