add-alias.asciidoc 2.7 KB

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