add-alias.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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::alias-exists.asciidoc[tag=index-alias-def]
  8. [source,js]
  9. ----
  10. PUT /twitter/_alias/alias1
  11. ----
  12. // CONSOLE
  13. // TEST[setup:twitter]
  14. [[add-alias-api-request]]
  15. ==== {api-request-title}
  16. `PUT /<index>/_alias/<alias>`
  17. `POST /<index>/_alias/<alias>`
  18. `PUT /<index>/_aliases/<alias>`
  19. `POST /<index>/_aliases/<alias>`
  20. [[add-alias-api-path-params]]
  21. ==== {api-path-parms-title}
  22. `<index>`::
  23. (Required, string)
  24. Comma-separated list or wildcard expression of index names
  25. to add to the alias.
  26. +
  27. To add all indices in the cluster to the alias,
  28. use a value of `_all`.
  29. `<alias>`::
  30. (Required, string)
  31. Name of the index alias to create or update.
  32. [[add-alias-api-query-params]]
  33. ==== {api-query-parms-title}
  34. include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  35. [[add-alias-api-request-body]]
  36. ==== {api-request-body-title}
  37. `filter`::
  38. (Required, query object)
  39. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-alias-filter]
  40. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-routing]
  41. [[add-alias-api-example]]
  42. ==== {api-examples-title}
  43. [[alias-adding]]
  44. ===== Add a time-based alias
  45. The following request creates an alias, `2030`,
  46. for the `logs_20302801` index.
  47. [source,js]
  48. --------------------------------------------------
  49. PUT /logs_20302801/_alias/2030
  50. --------------------------------------------------
  51. // CONSOLE
  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,js]
  58. --------------------------------------------------
  59. PUT /users
  60. {
  61. "mappings" : {
  62. "properties" : {
  63. "user_id" : {"type" : "integer"}
  64. }
  65. }
  66. }
  67. --------------------------------------------------
  68. // CONSOLE
  69. Then add the index alias for a specific user, `user_12`:
  70. [source,js]
  71. --------------------------------------------------
  72. PUT /users/_alias/user_12
  73. {
  74. "routing" : "12",
  75. "filter" : {
  76. "term" : {
  77. "user_id" : 12
  78. }
  79. }
  80. }
  81. --------------------------------------------------
  82. // CONSOLE
  83. // TEST[continued]
  84. [[alias-index-creation]]
  85. ===== Add an alias during index creation
  86. You can use the <<create-index-aliases,create index API>>
  87. to add an index alias during index creation.
  88. [source,js]
  89. --------------------------------------------------
  90. PUT /logs_20302801
  91. {
  92. "mappings" : {
  93. "properties" : {
  94. "year" : {"type" : "integer"}
  95. }
  96. },
  97. "aliases" : {
  98. "current_day" : {},
  99. "2030" : {
  100. "filter" : {
  101. "term" : {"year" : 2030 }
  102. }
  103. }
  104. }
  105. }
  106. --------------------------------------------------
  107. // CONSOLE