get-alias.asciidoc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. [[indices-get-alias]]
  2. === Get index alias API
  3. ++++
  4. <titleabbrev>Get index alias</titleabbrev>
  5. ++++
  6. Returns information about one or more index aliases.
  7. include::{docdir}/glossary.asciidoc[tag=index-alias-desc]
  8. [source,console]
  9. ----
  10. GET /twitter/_alias/alias1
  11. ----
  12. // TEST[setup:twitter]
  13. // TEST[s/^/PUT twitter\/_alias\/alias1\n/]
  14. [[get-alias-api-request]]
  15. ==== {api-request-title}
  16. `GET /_alias`
  17. `GET /_alias/<alias>`
  18. `GET /<index>/_alias/<alias>`
  19. [[get-alias-api-path-params]]
  20. ==== {api-path-parms-title}
  21. `<alias>`::
  22. (Optional, string)
  23. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-alias]
  24. +
  25. To retrieve information for all index aliases,
  26. use a value of `_all` or `*`.
  27. include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
  28. [[get-alias-api-query-params]]
  29. ==== {api-query-parms-title}
  30. include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  31. +
  32. Defaults to `true`.
  33. include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  34. +
  35. Defaults to `all`.
  36. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  37. include::{docdir}/rest-api/common-parms.asciidoc[tag=local]
  38. [[get-alias-api-example]]
  39. ==== {api-examples-title}
  40. [[get-alias-api-all-ex]]
  41. ===== Get all aliases for an index
  42. You can add index aliases during index creation
  43. using a <<indices-create-index,create index API>> request.
  44. The following create index API request creates the `logs_20302801` index
  45. with two aliases:
  46. * `current_day`
  47. * `2030`, which only returns documents
  48. in the `logs_20302801` index
  49. with a `year` field value of `2030`
  50. [source,console]
  51. --------------------------------------------------
  52. PUT /logs_20302801
  53. {
  54. "aliases" : {
  55. "current_day" : {},
  56. "2030" : {
  57. "filter" : {
  58. "term" : {"year" : 2030 }
  59. }
  60. }
  61. }
  62. }
  63. --------------------------------------------------
  64. The following get index alias API request returns all aliases
  65. for the index `logs_20302801`:
  66. [source,console]
  67. --------------------------------------------------
  68. GET /logs_20302801/_alias/*
  69. --------------------------------------------------
  70. // TEST[continued]
  71. The API returns the following response:
  72. [source,console-result]
  73. --------------------------------------------------
  74. {
  75. "logs_20302801" : {
  76. "aliases" : {
  77. "current_day" : {
  78. },
  79. "2030" : {
  80. "filter" : {
  81. "term" : {
  82. "year" : 2030
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. --------------------------------------------------
  90. [[get-alias-api-named-ex]]
  91. ===== Get a specific alias
  92. The following index alias API request returns the `2030` alias:
  93. [source,console]
  94. --------------------------------------------------
  95. GET /_alias/2030
  96. --------------------------------------------------
  97. // TEST[continued]
  98. The API returns the following response:
  99. [source,console-result]
  100. --------------------------------------------------
  101. {
  102. "logs_20302801" : {
  103. "aliases" : {
  104. "2030" : {
  105. "filter" : {
  106. "term" : {
  107. "year" : 2030
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. --------------------------------------------------
  115. [[get-alias-api-wildcard-ex]]
  116. ===== Get aliases based on a wildcard
  117. The following index alias API request returns any alias that begin with `20`:
  118. [source,console]
  119. --------------------------------------------------
  120. GET /_alias/20*
  121. --------------------------------------------------
  122. // TEST[continued]
  123. The API returns the following response:
  124. [source,console-result]
  125. --------------------------------------------------
  126. {
  127. "logs_20302801" : {
  128. "aliases" : {
  129. "2030" : {
  130. "filter" : {
  131. "term" : {
  132. "year" : 2030
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. --------------------------------------------------