add-alias.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. [[indices-add-alias]]
  2. === Add index alias API
  3. ++++
  4. <titleabbrev>Add 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-path-params]]
  20. ==== {api-path-parms-title}
  21. `<index>`::
  22. (Required, string)
  23. Comma-separated list or wildcard expression of index names
  24. to add to the alias.
  25. +
  26. To add all indices in the cluster to the alias,
  27. use a value of `_all`.
  28. +
  29. NOTE: You cannot add <<data-streams,data streams>> to an index alias.
  30. `<alias>`::
  31. (Required, string)
  32. Name of the index alias to create or update.
  33. [[add-alias-api-query-params]]
  34. ==== {api-query-parms-title}
  35. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  36. [[add-alias-api-request-body]]
  37. ==== {api-request-body-title}
  38. `filter`::
  39. (Required, query object)
  40. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-alias-filter]
  41. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-routing]
  42. [[add-alias-api-example]]
  43. ==== {api-examples-title}
  44. [[alias-adding]]
  45. ===== Add a time-based alias
  46. The following request creates an alias, `2030`,
  47. for the `logs_20302801` index.
  48. [source,console]
  49. --------------------------------------------------
  50. PUT /logs_20302801/_alias/2030
  51. --------------------------------------------------
  52. // TEST[s/^/PUT logs_20302801\n/]
  53. [[add-alias-api-user-ex]]
  54. ===== Add a user-based alias
  55. First, create an index, `users`,
  56. with a mapping for the `user_id` field:
  57. [source,console]
  58. --------------------------------------------------
  59. PUT /users
  60. {
  61. "mappings" : {
  62. "properties" : {
  63. "user_id" : {"type" : "integer"}
  64. }
  65. }
  66. }
  67. --------------------------------------------------
  68. Then add the index alias for a specific user, `user_12`:
  69. [source,console]
  70. --------------------------------------------------
  71. PUT /users/_alias/user_12
  72. {
  73. "routing" : "12",
  74. "filter" : {
  75. "term" : {
  76. "user_id" : 12
  77. }
  78. }
  79. }
  80. --------------------------------------------------
  81. // TEST[continued]
  82. [[alias-index-creation]]
  83. ===== Add an alias during index creation
  84. You can use the <<create-index-aliases,create index API>>
  85. to add an index alias during index creation.
  86. [source,console]
  87. --------------------------------------------------
  88. PUT /logs_20302801
  89. {
  90. "mappings": {
  91. "properties": {
  92. "year": { "type": "integer" }
  93. }
  94. },
  95. "aliases": {
  96. "current_day": {},
  97. "2030": {
  98. "filter": {
  99. "term": { "year": 2030 }
  100. }
  101. }
  102. }
  103. }
  104. --------------------------------------------------