get-alias.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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::{es-repo-dir}/glossary.asciidoc[tag=index-alias-desc]
  8. [source,console]
  9. ----
  10. GET /my-index-000001/_alias/alias1
  11. ----
  12. // TEST[setup:my_index]
  13. // TEST[s/^/PUT my-index-000001\/_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::{es-repo-dir}/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::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index]
  28. [[get-alias-api-query-params]]
  29. ==== {api-query-parms-title}
  30. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  31. +
  32. Defaults to `true`.
  33. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  34. +
  35. Defaults to `all`.
  36. `ignore_unavailable`::
  37. (Optional, Boolean)
  38. If `false`, requests that include a missing index in the `<index>` argument
  39. return an error. Defaults to `false`.
  40. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=local]
  41. [[get-alias-api-example]]
  42. ==== {api-examples-title}
  43. [[get-alias-api-all-ex]]
  44. ===== Get all aliases for an index
  45. You can add index aliases during index creation
  46. using a <<indices-create-index,create index API>> request.
  47. The following create index API request creates the `logs_20302801` index
  48. with two aliases:
  49. * `current_day`
  50. * `2030`, which only returns documents
  51. in the `logs_20302801` index
  52. with a `year` field value of `2030`
  53. [source,console]
  54. --------------------------------------------------
  55. PUT /logs_20302801
  56. {
  57. "aliases" : {
  58. "current_day" : {},
  59. "2030" : {
  60. "filter" : {
  61. "term" : {"year" : 2030 }
  62. }
  63. }
  64. }
  65. }
  66. --------------------------------------------------
  67. The following get index alias API request returns all aliases
  68. for the index `logs_20302801`:
  69. [source,console]
  70. --------------------------------------------------
  71. GET /logs_20302801/_alias/*
  72. --------------------------------------------------
  73. // TEST[continued]
  74. The API returns the following response:
  75. [source,console-result]
  76. --------------------------------------------------
  77. {
  78. "logs_20302801" : {
  79. "aliases" : {
  80. "current_day" : {
  81. },
  82. "2030" : {
  83. "filter" : {
  84. "term" : {
  85. "year" : 2030
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------
  93. [[get-alias-api-named-ex]]
  94. ===== Get a specific alias
  95. The following index alias API request returns the `2030` alias:
  96. [source,console]
  97. --------------------------------------------------
  98. GET /_alias/2030
  99. --------------------------------------------------
  100. // TEST[continued]
  101. The API returns the following response:
  102. [source,console-result]
  103. --------------------------------------------------
  104. {
  105. "logs_20302801" : {
  106. "aliases" : {
  107. "2030" : {
  108. "filter" : {
  109. "term" : {
  110. "year" : 2030
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. --------------------------------------------------
  118. [[get-alias-api-wildcard-ex]]
  119. ===== Get aliases based on a wildcard
  120. The following index alias API request returns any alias that begin with `20`:
  121. [source,console]
  122. --------------------------------------------------
  123. GET /_alias/20*
  124. --------------------------------------------------
  125. // TEST[continued]
  126. The API returns the following response:
  127. [source,console-result]
  128. --------------------------------------------------
  129. {
  130. "logs_20302801" : {
  131. "aliases" : {
  132. "2030" : {
  133. "filter" : {
  134. "term" : {
  135. "year" : 2030
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. --------------------------------------------------